外界訪問不了node
[root@k8s-master ~]# cat myweb-svc.yaml apiVersion: v1 kind: Service metadata: name: nginx spec: type: NodePort ports: - port: 80 nodePort: 30001 selector: app: myweb [root@k8s-master ~]# kubectl create -f myweb-svc.yaml service "nginx" created
[root@k8s-master ~]# kubectl get all NAME DESIRED CURRENT READY AGE rc/myweb 3 3 3 19m NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE svc/kubernetes 10.254.0.1 <none> 443/TCP 22h svc/nginx 10.254.205.175 <nodes> 80:30001/TCP 27s NAME READY STATUS RESTARTS AGE po/myweb-7m76h 1/1 Running 0 18m po/myweb-kzq8c 1/1 Running 0 18m po/myweb-mnf7x 1/1 Running 0 18m
一、修改成3000看看是否正常?nginx
[root@k8s-master ~]# vim myweb-svc.yaml 更改端口爲:3000 [root@k8s-master ~]# kubectl delete svc/nginx service "nginx" deleted [root@k8s-master ~]# kubectl create -f myweb-svc.yaml The Service "nginx" is invalid: spec.ports[0].nodePort: Invalid value: 3000: provided port is not in the valid range. The range of valid ports is 30000-32767
二、端口更改成30001web
[root@k8s-master ~]# vim myweb-svc.yaml 更改端口爲:30001 [root@k8s-master ~]# kubectl create -f myweb-svc.yaml service "nginx" created [root@k8s-master ~]# kubectl get all NAME DESIRED CURRENT READY AGE rc/myweb 3 3 3 25m NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE svc/kubernetes 10.254.0.1 <none> 443/TCP 22h svc/nginx 10.254.145.15 <nodes> 80:30027/TCP 8s NAME READY STATUS RESTARTS AGE po/myweb-7m76h 1/1 Running 0 24m po/myweb-kzq8c 1/1 Running 0 24m po/myweb-mnf7x 1/1 Running 0 25m
默認不填寫,自動分配30000-32767內任意一端口vim
一、修改svc副本數爲1api
[root@k8s-master ~]# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE myweb-7m76h 1/1 Running 0 26m 172.16.10.2 k8s-node1 myweb-kzq8c 1/1 Running 0 26m 172.16.48.4 k8s-node2 myweb-mnf7x 1/1 Running 0 26m 172.16.48.2 k8s-node2 [root@k8s-master ~]# kubectl edit rc myweb replicas: 1 replicationcontroller "myweb" edited [root@k8s-master ~]# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE myweb-mnf7x 1/1 Running 0 28m 172.16.48.2 k8s-node2 [root@k8s-master ~]# kubectl describe svc nginx Name: nginx Namespace: default Labels: <none> Selector: app=myweb Type: NodePort IP: 10.254.145.15 Port: <unset> 80/TCP NodePort: <unset> 30027/TCP Endpoints: 172.16.48.2:80 Session Affinity: None No events.
二、修改svc副本數爲5bash
[root@k8s-master ~]# kubectl edit rc myweb replicas: 5 replicationcontroller "myweb" edited [root@k8s-master ~]# kubectl describe svc nginx Name: nginx Namespace: default Labels: <none> Selector: app=myweb Type: NodePort IP: 10.254.145.15 Port: <unset> 80/TCP NodePort: <unset> 30027/TCP Endpoints: 172.16.10.2:80,172.16.10.3:80,172.16.48.2:80 + 1 more... Session Affinity: None No events. [root@k8s-master ~]# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE myweb-415zs 1/1 Running 0 9s 172.16.48.3 k8s-node2 myweb-7bw5f 1/1 Running 0 9s 172.16.10.3 k8s-node1 myweb-7kzh2 1/1 Running 0 9s 172.16.48.4 k8s-node2 myweb-j45xb 1/1 Running 0 9s 172.16.10.2 k8s-node1 myweb-mnf7x 1/1 Running 0 30m 172.16.48.2 k8s-node2
一、node1 web截圖app
二、node2 web截圖負載均衡