2017-09-14 176 views
0

我可以創建容器:揭露HELLO-minikube服務無法找到一個端口

$ kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port= 
deployment "hello-minikube" created 

而現在我想公開服務:

$ kubectl expose deployment hello-minikube --type=NodePort 
error: couldn't find port via --port flag or introspection 

即使我刪除,它仍然回來了自己的:

$ kubectl delete pod hello-minikube-2138963058-2szl7 
pod "hello-minikube-2138963058-2szl7" deleted 
[[email protected] ~] 
$ kubectl get pods 
NAME        READY  STATUS RESTARTS AGE 
hello-minikube-2138963058-nhh1q 1/1  Running 0   3m 

的是莢:

$ kubectl get pods 
NAME        READY  STATUS RESTARTS AGE 
hello-minikube-2138963058-2szl7 1/1  Running 0   16m 

及其說明:

$ kubectl describe pod hello-minikube-2138963058-2szl7 
Name:  hello-minikube-2138963058-2szl7 
Namespace: default 
Node:  minikube/192.168.42.196 
Start Time: Thu, 14 Sep 2017 23:20:03 +0200 
Labels:  pod-template-hash=2138963058 
     run=hello-minikube 
Annotations: kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"default","name":"hello-minikube-2138963058","uid":"2b37ca13-9968-11e7-a720-525400... 
Status:  Running 
IP:  172.17.0.3 
Created By: ReplicaSet/hello-minikube-2138963058 
Controlled By: ReplicaSet/hello-minikube-2138963058 
Containers: 
    hello-minikube: 
    Container ID: docker://5e4ba407d8869e6e843ec3d7876e953147cc01104e980c7febfea218808ab379 
    Image:  gcr.io/google_containers/echoserver:1.4 
    Image ID:  docker-pullable://gcr.io/google_containers/[email protected]:5d99aa1120524c801bc8c1a7077e8f5ec122ba16b6dda1a5d3826057f67b9bcb 
    Port:  <none> 
    State:  Running 
     Started:  Thu, 14 Sep 2017 23:20:05 +0200 
    Ready:  True 
    Restart Count: 0 
    Environment: <none> 
    Mounts: 
     /var/run/secrets/kubernetes.io/serviceaccount from default-token-t8qx7 (ro) 
Conditions: 
    Type  Status 
    Initialized True 
    Ready  True 
    PodScheduled True 
Volumes: 
    default-token-t8qx7: 
    Type: Secret (a volume populated by a Secret) 
    SecretName: default-token-t8qx7 
    Optional: false 
QoS Class: BestEffort 
Node-Selectors: <none> 
Tolerations: <none> 
Events: 
    FirstSeen LastSeen Count From   SubObjectPath   Type  Reason   Message 
    --------- -------- ----- ----   -------------   -------- ------   ------- 
    17m  17m  1 default-scheduler     Normal  Scheduled  Successfully assigned hello-minikube-2138963058-2szl7 to minikube 
    17m  17m  1 kubelet, minikube     Normal  SuccessfulMountVolume MountVolume.SetUp succeeded for volume "default-token-t8qx7" 
    17m  17m  1 kubelet, minikube spec.containers{hello-minikube} Normal  Pulled   Container image "gcr.io/google_containers/echoserver:1.4" already present on machine 
    17m  17m  1 kubelet, minikube spec.containers{hello-minikube} Normal  Created   Created container 
    17m  17m  1 kubelet, minikube spec.containers{hello-minikube} Normal  Started   Started container 

所有這一切都在Linux主機minikube。

回答

1

你得到這個錯誤,因爲你沒有在命令kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=設置的集裝箱港口作爲這樣的曝光命令不知道哪個集裝箱港口映射到節點端口,然後錯誤

假設80是端口號,然後再次運行公開,您必須設置確切的容器端口如下kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=80

見的我是如何能夠複製您的錯誤,然後修復

C:\Users\innocent.anigbo\.minikube>kubectl run hello-kube --image=gcr.io/google_ 
containers/echoserver:1.4 --port= 
deployment "hello-kube" created 

C:\Users\innocent.anigbo\.minikube>kubectl get pods 
NAME        READY  STATUS RESTARTS AGE 
hello-kube-1448409582-c9sm5  1/1  Running 0   1m 
hello-minikube-938614450-417hj 1/1  Running 1   8d 
hello-nginx-3322088713-c4rp4  1/1  Running 0   6m 

C:\Users\innocent.anigbo\.minikube>kubectl get deployment 
NAME    DESIRED CURRENT UP-TO-DATE AVAILABLE AGE 
hello-kube  1   1   1   1   2m 
hello-minikube 1   1   1   1   8d 
hello-nginx  1   1   1   1   7m 

C:\Users\innocent.anigbo\.minikube>kubectl get service 
NAME   CLUSTER-IP EXTERNAL-IP PORT(S)  AGE 
hello-nginx 10.0.0.136 <nodes>  80:32155/TCP 4m 
kubernetes 10.0.0.1  <none>  443/TCP  20d 

C:\Users\innocent.anigbo\.minikube>kubectl expose deployment hello-kube --type=N 
odePort 
error: couldn't find port via --port flag or introspection 
See 'kubectl expose -h' for help and examples. 

C:\Users\innocent.anigbo\.minikube>kubectl delete deployment hello-kube 
deployment "hello-kube" deleted 

C:\Users\innocent.anigbo\.minikube>kubectl get pods 
NAME        READY  STATUS RESTARTS AGE 
hello-minikube-938614450-417hj 1/1  Running 1   8d 
hello-nginx-3322088713-c4rp4  1/1  Running 0   11m 

C:\Users\innocent.anigbo\.minikube>kubectl run hello-kube --image=gcr.io/google_ 
containers/echoserver:1.4 --port=80 
deployment "hello-kube" created 

C:\Users\innocent.anigbo\.minikube>kubectl get pods 
NAME        READY  STATUS RESTARTS AGE 
hello-kube-2715294448-0rxf2  1/1  Running 0   3s 
hello-minikube-938614450-417hj 1/1  Running 1   8d 
hello-nginx-3322088713-c4rp4  1/1  Running 0   11m 

C:\Users\innocent.anigbo\.minikube>kubectl expose deployment hello-kube --type=N 
odePort 
service "hello-kube" exposed 

C:\Users\innocent.anigbo\.minikube>kubectl get service 
NAME   CLUSTER-IP EXTERNAL-IP PORT(S)  AGE 
hello-kube 10.0.0.137 <nodes>  80:30004/TCP 3s 
hello-nginx 10.0.0.136 <nodes>  80:32155/TCP 9m 
kubernetes 10.0.0.1  <none>  443/TCP  20d 
+0

我可以公開服務'kubectl運行hello-minikube --image = gcr.io/google_containers/echoserver:1.4 --port = 82'和'kubectl公開部署hello-minikube --type = NodePort'顯示服務' $ kubectl get services NAME CLUSTER-IP EXTERNAL-IP PORT(S)AGE hello-minikube 10.0.0.81 82:32515/TCP 4h'但試圖連接失敗'$ curl $(minikube service hello-minikube --url ) curl:(7)無法連接到192.168.42.196端口32515:連接被拒絕# – Stephane

+0

但是,如果不是使用端口82,我使用端口8080然後工作。我以爲我可以在這裏選擇我自己的港口。情況並非如此? – Stephane

+1

不,你不能使用你自己的端口或任何隨機端口。這必須是容器偵聽流量的端口,如圖像「echoserver:1.4」中所示。您將從記錄圖像的回購站獲取此端口號。 8080只能運行,因爲你很幸運已經猜到了正確的端口。下次更好時,您只需從圖像文檔中檢查它,以使其更容易。 –

1

您的容器正在重新出現,因爲部署將爲該容器創建一個副本集,如果當前的容器終止,將創建一個新的容器。

運行此操作檢查是否部署了副本集。

kubectl get rs 

理論上,應該刪除整個部署

kubectl delete deployment <name> 
+0

作爲K8S小白,我不知道有足夠的瞭解環境和莢刪除了正確的一步一步波紋管。你的答案加上Innocent Anigbo的上述答案解決了我的問題。 – Stephane