~]# cd /opt/k8s/work
]# cat > nginx-test.yml <<EOF
apiVersion: v1
kind: Service
metadata:
name: nginx
namespace: demo-ns
labels:
app: nginx
spec:
type: NodePort
selector:
app: nginx
ports:
- name: http
port: 80
targetPort: 80
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: nginx
namespace: demo-ns
labels:
addonmanager.kubernetes.io/mode: Reconcile
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: my-nginx
image: nginx
ports:
- containerPort: 80
EOF
]# kubectl create ns demo-ns
]# kubectl apply -f nginx-test.yml
service/nginx-ds created
daemonset.apps/nginx-ds created
]# kubectl get pods -n demo-ns -o wide -l app=nginx
# 在所有 worker 上分别 ping 上面 Pod IP,看是否连通
]# for node_ip in ${NODE_IPS[@]}
do
echo ">>> ${node_ip}"
ssh ${node_ip} "ping -c 1 10.68.100.192"
ssh ${node_ip} "ping -c 1 10.68.194.65"
ssh ${node_ip} "ping -c 1 10.68.126.0"
done
]# kubectl get svc -n demo-ns -l app=nginx
#在所有节点上 curl Service IP
]# for node_ip in ${NODE_IPS[@]}
do
echo ">>> ${node_ip}"
ssh ${node_ip} "curl -s 10.254.236.145"
done
]# for node_ip in ${NODE_IPS[@]}
do
echo ">>> ${node_ip}"
ssh ${node_ip} "curl -s ${node_ip}:30888"
done