我正在尝试找到一种方法来确定“ kubectl port-forward”命令的状态。 有一种方法可以确定Pod,节点的就绪状态:例如“ kubectl get pods”等...
是否可以确定kubectl port-forward命令是否已完成并准备工作?
谢谢。
答案 0 :(得分:0)
Readiness and liveness probes
是集群检查单个Pod状态的方式。
您需要在清单中定义它们:
apiVersion: v1
kind: Pod
metadata:
name: goproxy
labels:
app: goproxy
spec:
containers:
- name: goproxy
image: k8s.gcr.io/goproxy:0.1
ports:
- containerPort: 8080
readinessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 15
periodSeconds: 20
当您的吊舱开始运作时,kubectl port-forward
将立即工作。
您可以在以下位置阅读一些理论
https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/
答案 1 :(得分:0)
直接回答您的问题-不,您无法确定kubectl port-forward
命令的状态。
确定后台运行情况的唯一方法是检查此命令的输出。
输出将类似于:
Forwarding from 127.0.0.1:6379 -> 6379
Forwarding from [::1]:6379 -> 6379
我可能建议使用service type NodePort而不是port-forward
。
使用NodePort
,您可以将应用程序公开为服务,并可以从Kubernetes外部进行访问。
有关更多示例,use this url。
答案 2 :(得分:0)
I have the same understanding as you @VKR.
The way that I choose to solve this was to have a loop with a curl every second to check the status of the forwarded port. It works but I had hoped for a prebaked solution to this.
do curl:6379
timer=0
while curl is false and timer <100
timer++
curl:6379
sleep 1
Thank you @Nicola and @David, I will keep those in mind when I get past development testing.