手动搭建k8s-1.16.6高可用集群之验证集群功能

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

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

一、检查节点状态

$ kubectl get nodes
NAME     STATUS   ROLES    AGE     VERSION
k8s-01   Ready    <none>   4h45m   v1.16.6
k8s-02   Ready    <none>   4h45m   v1.16.6
k8s-03   Ready    <none>   4h45m   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
service/nginx-ds created
daemonset.apps/nginx-ds created

四、 检查各节点的 Pod IP 连通性

$ kubectl get pods  -o wide -l app=nginx-ds
NAME             READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx-ds-25h8m   1/1     Running   0          61m   172.30.144.2   k8s-01   <none>           <none>
nginx-ds-7whgp   1/1     Running   0          61m   172.30.176.2   k8s-02   <none>           <none>
nginx-ds-9b85z   1/1     Running   0          61m   172.30.200.2   k8s-03   <none>           <none>

可以看到,nginx-ds的 Pod IP 分别是172.30.144.2、172.30.176.2、172.30.200.2。在所有 Node 上分别 ping 上面三个 Pod IP,看是否连通:

cat > deploy.sh << "EOF"
#!/bin/bash
cd /opt/k8s/work
source /opt/k8s/bin/environment.sh
for node_ip in ${NODE_IPS[@]}
do
    echo ">>> ${node_ip}"
    ssh ${node_ip} "ping -c 1 172.30.144.2"
    ssh ${node_ip} "ping -c 1 172.30.176.2"
    ssh ${node_ip} "ping -c 1 172.30.200.2"
done
EOF

五、 检查服务 IP 和端口可达性

$ kubectl get svc -l app=nginx-ds  
NAME       TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
nginx-ds   NodePort   10.254.83.21   <none>        80:31573/TCP   66m

可见:

  • Service Cluster IP:10.254.83.21
  • 服务端口:80
  • NodePort 端口:31573

在所有 Node 上 curl Service IP:

cat > deploy.sh << "EOF"
#!/bin/bash
cd /opt/k8s/work
source /opt/k8s/bin/environment.sh
for node_ip in ${NODE_IPS[@]}
do
    echo ">>> ${node_ip}"
    ssh ${node_ip} "curl -s 10.254.83.21"
done
EOF

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

你可能感兴趣的:(#)