$ kubectl cluster-info Kubernetes master is running at https://localhost:6443 KubeDNS is running at https://localhost:6443/api/v1/namespaces/kube-system/services/kube-dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
$ kubectl get nodes NAME STATUS ROLES AGE VERSION docker-for-desktop Ready master 9d v1.9.2
$ kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
secret “kubernetes-dashboard-certs” created
serviceaccount “kubernetes-dashboard” created
role “kubernetes-dashboard-minimal” created
rolebinding “kubernetes-dashboard-minimal” created
deployment “kubernetes-dashboard” created
service “kubernetes-dashboard” created
$ kubectl describe pod hello-nginx-556b7bf96-2xw8f Name: hello-nginx-556b7bf96-2xw8f Namespace: default Node: docker-for-desktop/192.168.65.3 Start Time: Tue, 20 Feb 2018 22:34:19 -0800 Labels: pod-template-hash=112636952 run=hello-nginx Annotations: <none> Status: Running IP: 10.1.0.54 Controlled By: ReplicaSet/hello-nginx-556b7bf96 Containers: hello-nginx: Container ID: docker://5c5f68348ed8a204dcce089a21d71e36cbfdb6c7955fd28a7f148d5f44662861 Image: nginx Image ID: docker-pullable://nginx@sha256:65f0ed5362b39c16cad51f27217c12ac9dd0db4dc47b0197969885f05198d4d8 Port: 80/TCP State: Running Started: Tue, 20 Feb 2018 22:34:37 -0800 Ready: True Restart Count: 0 Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-m99ws (ro) Conditions: Type Status Initialized True Ready True PodScheduled True Volumes: default-token-m99ws: Type: Secret (a volume populated by a Secret) SecretName: default-token-m99ws Optional: false QoS Class: BestEffort Node-Selectors: <none> Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s node.kubernetes.io/unreachable:NoExecute for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 15m default-scheduler Successfully assigned hello-nginx-556b7bf96-2xw8f to docker-for-desktop Normal SuccessfulMountVolume 15m kubelet, docker-for-desktop MountVolume.SetUp succeeded for volume "default-token-m99ws" Normal Pulling 15m kubelet, docker-for-desktop pulling image "nginx" Normal Pulled 15m kubelet, docker-for-desktop Successfully pulled image "nginx" Normal Created 15m kubelet, docker-for-desktop Created container Normal Started 15m kubelet, docker-for-desktop Started container
通过外部访问
之前我们提到过,可以用 port-forward pod 来实现外部访问:
1 2 3 4 5 6
$ kubectl get pods NAME READY STATUS RESTARTS AGE hello-nginx-556b7bf96-2xw8f 1/1 Running 0 46m
$ kubectl port-forward hello-nginx-556b7bf96-2xw8f 8080:8080 Forwarding from 127.0.0.1:8080 -> 8080
但这只暴露特定 pod 的端口,在实际中并不实用。
所以我们换一个方法,把 deployment 暴露成一个服务,供外部访问:
1 2 3 4 5 6 7 8 9 10 11
$ kubectl get deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE hello-nginx 1 1 1 1 18m
$ kubectl expose deployment hello-nginx --type=NodePort --name=hello-nginx-service service "hello-nginx-service" exposed
$ kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello-nginx-service NodePort 10.109.0.203 <none> 80:30351/TCP 30s kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 10d