日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

k8s部署nginx集群

發布時間:2024/2/28 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 k8s部署nginx集群 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

環境:

兩臺虛擬機,

10.10.20.203 部署docker、etcd、flannel、kube-apiserver、kube-controller-manager、kube-scheduler

10.10.20.206?部署docker、flannel、kubelet、kube-proxy

?

1、創建nginx-rc.yaml

?

apiVersion: v1 kind: ReplicationController metadata:name: nginx-controller spec:replicas: 2selector:name: nginxtemplate:metadata:labels:name: nginxspec:containers:- name: nginximage: nginxports:- containerPort: 80

?

2、創建nginx-service-nodeport.yaml

?

apiVersion: v1 kind: Service metadata:name: nginx-service-nodeport spec:ports:- port: 8000targetPort: 80protocol: TCPtype: NodePortselector:name: nginx

3、創建pod

kubectl create -f nginx-rc.yaml

4、創建service

kubectl create -f nginx-service-nodeport.yaml

5、查看pod

[root@k8s-master ~]# kubectl get pods NAME READY STATUS RESTARTS AGE nginx-controller-v40nj 1/1 Running 1 1h nginx-controller-zxdzh 1/1 Running 1 1h

?

[root@k8s-master ~]# kubectl describe pod nginx-controller-v40nj Name: nginx-controller-v40nj Namespace: default Node: k8s-slave1-206/60.19.29.21 Start Time: Thu, 11 Aug 2016 19:02:20 -0700 Labels: name=nginx Status: Running IP: 10.0.83.3 Controllers: ReplicationController/nginx-controller Containers:nginx:Container ID: docker://269adc9b693aba0356ba18e4253c2b498fc7b7a8ce0af83857fcfd6b70e6ef03Image: nginxImage ID: docker://sha256:0d409d33b27e47423b049f7f863faa08655a8c901749c2b25b93ca67d01a470dPort: 80/TCPState: RunningStarted: Thu, 11 Aug 2016 20:49:27 -0700Last State: TerminatedReason: CompletedExit Code: 0Started: Thu, 11 Aug 2016 19:03:44 -0700Finished: Thu, 11 Aug 2016 20:12:12 -0700Ready: TrueRestart Count: 1Environment Variables: <none> Conditions:Type StatusInitialized TrueReady TruePodScheduled True No volumes. QoS Tier: BestEffort Events:FirstSeen LastSeen Count From SubobjectPath Type Reason Message--------- -------- ----- ---- ------------- -------- ------ -------5m 5m 1 {kubelet k8s-slave1-206} spec.containers{nginx} Normal Pulling pulling image "nginx"5m 5m 2 {kubelet k8s-slave1-206} Warning MissingClusterDNS kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy.5m 5m 1 {kubelet k8s-slave1-206} spec.containers{nginx} Normal Pulled Successfully pulled image "nginx"5m 5m 1 {kubelet k8s-slave1-206} spec.containers{nginx} Normal Created Created container with docker id 269adc9b693a5m 5m 1 {kubelet k8s-slave1-206} spec.containers{nginx} Normal Started Started container with docker id 269adc9b693a

?

6、查看service

[root@k8s-master ~]# kubectl get service NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes 10.254.0.1 <none> 443/TCP 16h nginx-service-nodeport 10.254.29.72 <nodes> 8000/TCP 49m

?

[root@k8s-master ~]# kubectl describe service nginx-service-nodeport Name: nginx-service-nodeport Namespace: default Labels: <none> Selector: name=nginx Type: NodePort IP: 10.254.29.72 Port: <unset> 8000/TCP NodePort: <unset> 31152/TCP Endpoints: 10.0.83.2:80,10.0.83.3:80 Session Affinity: None No events.

?

7、測試service是否好用

因為service使用的是NodePort方式,所以在任何一個節點訪問31152這個端口都可以訪問nginx

?

$ curl 10.10.20.203:31152 <!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>

?

?

$ curl 10.10.20.206:31152 <!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>

?

總結

以上是生活随笔為你收集整理的k8s部署nginx集群的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。