本文档使用 daemonset 验证 master 和 worker 节点是否工作正常
1、检查节点状态
kubectl get nodes
NAME STATUS ROLES AGE VERSION
kube-node1 Ready <none> 3h v1.10.4
kube-node2 Ready <none> 3h v1.10.4
kube-node3 Ready <none> 3h v1.10.4
都为 Ready 时正常。
2、创建测试文件
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
3、执行定义文件
启动之前,可以先将上边定义的镜像 pull 下来
kubectl create -f nginx-ds.yml
service "nginx-ds" created
daemonset.extensions "nginx-ds" created
4、检查各 Node 上的 Pod IP 连通性
kubectl get pods -o wide|grep nginx-ds
nginx-ds-bw72r 1/1 Running 0 6h 172.30.29.2 kube-node3
nginx-ds-fbx76 1/1 Running 0 6h 172.30.84.2 kube-node1
nginx-ds-jbjzg 1/1 Running 0 6h 172.30.8.2 kube-node2
可见,nginx-ds 的 Pod IP 分别是 172.30.84.2、172.30.8.2、172.30.29.2,在所有 Node 上分别 ping 这三个 IP,看是否连通:
cat > magic68_check_Node_server.sh << "EOF"
#!/bin/bash
source /opt/k8s/bin/environment.sh
for node_ip in ${NODE_IPS[@]}
do
echo ">>> ${node_ip}"
ssh ${node_ip} "ping -c 1 172.30.84.2"
ssh ${node_ip} "ping -c 1 172.30.8.2"
ssh ${node_ip} "ping -c 1 172.30.29.2"
done
EOF
5、检查服务 IP 和端口可达性
kubectl get svc |grep nginx-ds
nginx-ds NodePort 10.254.110.153 <none> 80:8781/TCP 6h
可见:
- Service Cluster IP:10.254.110.153
- 服务端口:80
- NodePort 端口:8781
在所有 Node 上 curl Service IP:
cat > magic69_All_Node_CurlService.sh << "EOF"
#!/bin/bash
# 在所有 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.110.153"
done
EOF
预期输出 nginx 欢迎页面内容
6、检查服务的 NodePort 可达性
在所有 Node 上执行
cat > magic70_All_Node_Run.sh << "EOF"
#!/bin/bash
source /opt/k8s/bin/environment.sh
for node_ip in ${NODE_IPS[@]}
do
echo ">>> ${node_ip}"
ssh ${node_ip} "curl ${node_ip}:8781"
done
EOF
预期输出 nginx 欢迎页面内容
网友评论