08.验证集群功能

本文档使用 daemonset 验证 master 和 worker 节点是否工作正常。

检查节点状态

  1. $ kubectl get nodes
  2. NAME STATUS ROLES AGE VERSION
  3. kube-node1 Ready <none> 3h v1.10.4
  4. kube-node2 Ready <none> 3h v1.10.4
  5. kube-node3 Ready <none> 3h v1.10.4

都为 Ready 时正常。

创建测试文件

  1. $ cat > nginx-ds.yml <<EOF
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. name: nginx-ds
  6. labels:
  7. app: nginx-ds
  8. spec:
  9. type: NodePort
  10. selector:
  11. app: nginx-ds
  12. ports:
  13. - name: http
  14. port: 80
  15. targetPort: 80
  16. ---
  17. apiVersion: extensions/v1beta1
  18. kind: DaemonSet
  19. metadata:
  20. name: nginx-ds
  21. labels:
  22. addonmanager.kubernetes.io/mode: Reconcile
  23. spec:
  24. template:
  25. metadata:
  26. labels:
  27. app: nginx-ds
  28. spec:
  29. containers:
  30. - name: my-nginx
  31. image: nginx:1.7.9
  32. ports:
  33. - containerPort: 80
  34. EOF

执行定义文件

  1. $ kubectl create -f nginx-ds.yml
  2. service "nginx-ds" created
  3. daemonset.extensions "nginx-ds" created

检查各 Node 上的 Pod IP 连通性

  1. $ kubectl get pods -o wide|grep nginx-ds
  2. nginx-ds-dbn97 1/1 Running 0 2m 172.30.29.2 kube-node2
  3. nginx-ds-rk777 1/1 Running 0 2m 172.30.81.2 kube-node1
  4. nginx-ds-tr9g5 1/1 Running 0 2m 172.30.39.2 kube-node3

可见,nginx-ds 的 Pod IP 分别是 172.30.39.2172.30.81.2172.30.29.2,在所有 Node 上分别 ping 这三个 IP,看是否连通:

  1. source /opt/k8s/bin/environment.sh
  2. for node_ip in ${NODE_IPS[@]}
  3. do
  4. echo ">>> ${node_ip}"
  5. ssh ${node_ip} "ping -c 1 172.30.39.2"
  6. ssh ${node_ip} "ping -c 1 172.30.81.2"
  7. ssh ${node_ip} "ping -c 1 172.30.29.2"
  8. done

检查服务 IP 和端口可达性

  1. $ kubectl get svc |grep nginx-ds
  2. nginx-ds NodePort 10.254.254.228 <none> 80:8900/TCP 4m

可见:

  • Service Cluster IP:10.254.254.228
  • 服务端口:80
  • NodePort 端口:8900

在所有 Node 上 curl Service IP:

  1. source /opt/k8s/bin/environment.sh
  2. for node_ip in ${NODE_IPS[@]}
  3. do
  4. echo ">>> ${node_ip}"
  5. ssh ${node_ip} "curl 10.254.254.228"
  6. done

预期输出 nginx 欢迎页面内容。

检查服务的 NodePort 可达性

在所有 Node 上执行:

  1. source /opt/k8s/bin/environment.sh
  2. for node_ip in ${NODE_IPS[@]}
  3. do
  4. echo ">>> ${node_ip}"
  5. ssh ${node_ip} "curl ${node_ip}:8900"
  6. done

预期输出 nginx 欢迎页面内容。