第七章 完成kubernetes叢集部署並驗證
阿新 • • 發佈:2021-07-16
在其中一運算個節點上操作就行
建立nginx資源配置清單的yaml檔案
[root@hdss7-21 ~]# vim /opt/kubernetes/conf/nginx-ds.yaml apiVersion: extensions/v1beta1 kind: DaemonSet metadata: name: nginx-ds spec: template: metadata: labels: app: nginx-ds spec: containers: - name: my-nginx image: harbor.od.com/public/nginx:v1.7.9 ports: - containerPort: 80
建立nginx資源
[root@hdss7-21 ~]# kubectl create -f /opt/kubernetes/conf/nginx-ds.yaml
daemonset.extensions/nginx-ds created
檢視pod
[root@hdss7-21 ~]# kubectl get pods NAME READY STATUS RESTARTS AGE nginx-ds-4ln28 1/1 Running 0 38s nginx-ds-spdgm 1/1 Running 0 38s [root@hdss7-21 ~]# kubectl get pods -owide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-ds-4ln28 1/1 Running 0 56s 172.7.22.2 hdss7-22.host.com <none> <none> nginx-ds-spdgm 1/1 Running 0 56s 172.7.21.2 hdss7-21.host.com <none> <none>
在21主機上和22主機上只能訪問自己建立的容器主機
例如,在21上訪問172.7.21.2可以正常訪問
[root@hdss7-21 ~]# curl 172.7.21.2 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
訪問172.7.22.2(宿主機在10.4.7.22上)卻無法連線
[root@hdss7-21 ~]# curl 172.7.22.2
^C
原因是我們利用docker跨宿主機還不能通訊,後面介紹的flannel可以解決跨主機通訊問題