驗證集羣功能

說明:本部署文章參照了 https://github.com/opsnull/follow-me-install-kubernetes-cluster ,歡迎給做者star

本文檔使用 daemonset 驗證 master 和 worker 節點是否工做正常。node

注意:若是沒有特殊指明,本文檔的全部操做均在 k8s-master1 節點上執行,而後遠程分發文件和執行命令nginx

檢查節點狀態

[root@k8s-master1 ~]# kubectl get nodes
NAME        STATUS   ROLES    AGE   VERSION
k8s-node1   Ready    <none>   64m   v1.14.1
k8s-node2   Ready    <none>   64m   v1.14.1
k8s-node3   Ready    <none>   64m   v1.14.1

都爲 Ready 時正常。git

建立測試文件

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

檢查各 Node 上的 Pod IP 連通性

kubectl get pods  -o wide|grep nginx-ds
nginx-ds-69tzf   1/1     Running   0          2m34s   172.30.112.2   k8s-node3   <none>           <none>
nginx-ds-fl6r7   1/1     Running   0          2m14s   172.30.16.2    k8s-node1   <none>           <none>
nginx-ds-xqp8m   1/1     Running   0          2m34s   172.30.248.2   k8s-node2   <none>           <none>

可見,nginx-ds 的 Pod IP 分別是 172.30.112.2172.30.16.2172.30.248.2,在全部 Node 上分別 ping 這三個 IP,看是否連通:github

source /opt/k8s/bin/environment.sh
for node_ip in 192.168.161.170 192.168.161.171 192.168.161.172
  do
    echo ">>> ${node_ip}"
    ssh ${node_ip} "ping -c 1 172.30.112.2"
    ssh ${node_ip} "ping -c 1 172.30.16.2"
    ssh ${node_ip} "ping -c 1 172.30.248.2"
  done

檢查服務 IP 和端口可達性

[root@k8s-master1 work]# kubectl get svc |grep nginx-ds
nginx-ds     NodePort    10.254.250.3   <none>        80:32218/TCP   4m37s

可見:api

  • Service Cluster IP:10.254.250.3
  • 服務端口:80
  • NodePort 端口:32218

在全部 Node 上 curl Service IP:app

source /opt/k8s/bin/environment.sh
for node_ip in 192.168.161.170 192.168.161.171 192.168.161.172
  do
    echo ">>> ${node_ip}"
    ssh ${node_ip} "curl 10.254.250.3"
  done

預期輸出 nginx 歡迎頁面內容。ssh

相關文章
相關標籤/搜索