Skip to content

Latest commit

 

History

History
140 lines (112 loc) · 3.18 KB

08.验证集群功能.md

File metadata and controls

140 lines (112 loc) · 3.18 KB

tags: verify

08.验证集群功能

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

注意:如果没有特殊指明,本文档的所有操作均在 zhangjun-k8s01 节点上执行,然后远程分发文件和执行命令。

检查节点状态

$ kubectl get nodes
NAME             STATUS   ROLES    AGE    VERSION
zhangjun-k8s01   Ready    <none>   154m   v1.14.2
zhangjun-k8s02   Ready    <none>   154m   v1.14.2
zhangjun-k8s03   Ready    <none>   154m   v1.14.2

都为 Ready 时正常。

创建测试文件

cd /opt/k8s/work
cat > nginx-ds.yml <<EOF
apiVersion: v1
kind: Service
metadata:
  name: nginx-ds
  labels:
    app: nginx-ds
spec:
  type: NodePort
  selector:
    app: nginx-ds
  ports:
  - name: http
    port: 80
    targetPort: 80
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: nginx-ds
  labels:
    addonmanager.kubernetes.io/mode: Reconcile
spec:
  template:
    metadata:
      labels:
        app: nginx-ds
    spec:
      containers:
      - name: my-nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
EOF

执行测试

kubectl create -f nginx-ds.yml

检查各节点的 Pod IP 连通性

$ kubectl get pods  -o wide|grep nginx-ds
nginx-ds-cr9n2   1/1     Running   0          2m7s   172.30.32.2    zhangjun-k8s02   <none>           <none>
nginx-ds-nf7sk   1/1     Running   0          2m7s   172.30.184.2   zhangjun-k8s03   <none>           <none>
nginx-ds-scpcn   1/1     Running   0          2m7s   172.30.80.2    zhangjun-k8s01   <none>           <none>

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

source /opt/k8s/bin/environment.sh
for node_ip in ${NODE_IPS[@]}
  do
    echo ">>> ${node_ip}"
    ssh ${node_ip} "ping -c 1 172.30.32.2"
    ssh ${node_ip} "ping -c 1 172.30.184.2"
    ssh ${node_ip} "ping -c 1 172.30.80.2"
  done

检查服务 IP 和端口可达性

$ kubectl get svc |grep nginx-ds
nginx-ds     NodePort    10.254.13.141   <none>        80:31858/TCP   2m58s

可见:

  • Service Cluster IP:10.254.13.141
  • 服务端口:80
  • NodePort 端口:31858

在所有 Node 上 curl Service IP:

source /opt/k8s/bin/environment.sh
for node_ip in ${NODE_IPS[@]}
  do
    echo ">>> ${node_ip}"
    ssh ${node_ip} "curl -s 10.254.13.141"
  done

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

检查服务的 NodePort 可达性

在所有 Node 上执行:

source /opt/k8s/bin/environment.sh
for node_ip in ${NODE_IPS[@]}
  do
    echo ">>> ${node_ip}"
    ssh ${node_ip} "curl -s ${node_ip}:31858"
  done

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