Skip to content

Latest commit

 

History

History
145 lines (117 loc) · 3.44 KB

07.验证集群功能.md

File metadata and controls

145 lines (117 loc) · 3.44 KB

tags: verify

07. 验证集群功能

本文档验证 K8S 集群是否工作正常。

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

检查节点状态

$ kubectl get nodes
NAME              STATUS   ROLES    AGE   VERSION
zhangjun-k8s-01   Ready    <none>   15m   v1.16.6
zhangjun-k8s-02   Ready    <none>   15m   v1.16.6
zhangjun-k8s-03   Ready    <none>   15m   v1.16.6

都为 Ready 且版本为 v1.16.6 时正常。

创建测试文件

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: apps/v1
kind: DaemonSet
metadata:
  name: nginx-ds
  labels:
    addonmanager.kubernetes.io/mode: Reconcile
spec:
  selector:
    matchLabels:
      app: nginx-ds
  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 -l app=nginx-ds
NAME             READY   STATUS    RESTARTS   AGE   IP               NODE              NOMINATED NODE   READINESS GATES
nginx-ds-j7v5g   1/1     Running   0          61s   172.30.244.1     zhangjun-k8s-01   <none>           <none>
nginx-ds-js8g8   1/1     Running   0          61s   172.30.82.129    zhangjun-k8s-02   <none>           <none>
nginx-ds-n2p4x   1/1     Running   0          61s   172.30.184.130   zhangjun-k8s-03   <none>           <none>

在所有 Node 上分别 ping 上面三个 Pod 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.244.1"
    ssh ${node_ip} "ping -c 1 172.30.82.129"
    ssh ${node_ip} "ping -c 1 172.30.184.130"
  done

检查服务 IP 和端口可达性

$ kubectl get svc -l app=nginx-ds                                                                                                                    
NAME       TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
nginx-ds   NodePort   10.254.116.22   <none>        80:30562/TCP   2m7s

可见:

  • Service Cluster IP:10.254.116.22
  • 服务端口:80
  • NodePort 端口:30562

在所有 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.116.22"
  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}:30562"
  done

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