tags: verify
本文档使用 daemonset 验证 master 和 worker 节点是否工作正常。
注意:如果没有特殊指明,本文档的所有操作均在 m7-autocv-gpu01 节点上执行,然后远程分发文件和执行命令。
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
m7-autocv-gpu03 Ready <none> 17m v1.12.3
m7-autocv-gpu02 Ready <none> 17m v1.12.3
m7-autocv-gpu01 Ready <none> 13m v1.12.3
都为 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
$ kubectl get pods -o wide|grep nginx-ds
nginx-ds-dbn97 1/1 Running 0 2m 172.30.29.2 m7-autocv-gpu02
nginx-ds-rk777 1/1 Running 0 2m 172.30.81.2 m7-autocv-gpu01
nginx-ds-tr9g5 1/1 Running 0 2m 172.30.39.2 m7-autocv-gpu03
可见,nginx-ds 的 Pod IP 分别是 172.30.39.2
、172.30.81.2
、172.30.29.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.39.2"
ssh ${node_ip} "ping -c 1 172.30.81.2"
ssh ${node_ip} "ping -c 1 172.30.29.2"
done
$ kubectl get svc |grep nginx-ds
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:
source /opt/k8s/bin/environment.sh
for node_ip in ${NODE_IPS[@]}
do
echo ">>> ${node_ip}"
ssh ${node_ip} "curl 10.254.254.228"
done
预期输出 nginx 欢迎页面内容。
在所有 Node 上执行:
source /opt/k8s/bin/environment.sh
for node_ip in ${NODE_IPS[@]}
do
echo ">>> ${node_ip}"
ssh ${node_ip} "curl ${node_ip}:8900"
done
预期输出 nginx 欢迎页面内容。