如果没有特殊指明,所有操作均在 zhaoyixin-k8s-01 节点上执行。
检查节点状态
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
zhaoyixin-k8s-01 Ready <none> 127m v1.16.6
zhaoyixin-k8s-02 Ready <none> 127m v1.16.6
zhaoyixin-k8s-03 Ready <none> 127m 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-9r6q7 1/1 Running 0 2m33s 172.30.219.2 zhaoyixin-k8s-02 <none> <none>
nginx-ds-dkc8p 1/1 Running 0 2m33s 172.30.200.1 zhaoyixin-k8s-03 <none> <none>
nginx-ds-lp2p9 1/1 Running 0 2m33s 172.30.180.65 zhaoyixin-k8s-01 <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.180.65"
ssh ${node_ip} "ping -c 1 172.30.219.2"
ssh ${node_ip} "ping -c 1 172.30.200.1"
done
检查服务 IP 和端口可达性
$ kubectl get svc -l app=nginx-ds
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-ds NodePort 10.254.134.181 <none> 80:30526/TCP 3m44s
- Service Cluster IP:10.254.134.181
- 服务端口:80
- NodePort 端口:30526
在所有 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.134.181"
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}:30526"
done
预期输出 nginx 欢迎页面内容。