创建2个pod的nginx service

[root@node1 data]# kubectl run nginx –replicas=2 –labels="run=load-balancer-example" –image=nginx:1.9 –port=80

deployment "nginx" created

[root@node1 yaml]# kubectl get pod –all-namespaces -o wide|grep nginx

default nginx-3431010723-6kv1z 1/1 Running 2 1h 10.244.5.6 node5

default nginx-3431010723-bw22q 1/1 Running 2 1h 10.244.3.14 node4

[root@node1 kube-config]# kubectl expose deployment nginx –type=NodePort –name=example-service

service "example-service" exposed

[root@node1 kube-config]# kubectl describe svc example-service

Name: example-service

Namespace: default

Labels: run=load-balancer-example

Annotations:

Selector: run=load-balancer-example

Type: NodePort

IP: 10.105.170.116

Port: 80/TCP

NodePort: 30457/TCP

Endpoints: 10.244.3.14:80,10.244.5.6:80

Session Affinity: None

Events:

测试nginx服务

[root@node1 yaml]# curl 10.105.170.116:80

Welcome to nginx!

body {

width: 35em;

margin: 0 auto;

font-family: Tahoma, Verdana, Arial, sans-serif;

}

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and

working. Further configuration is required.

For online documentation and support please refer to

nginx.org.

Commercial support is available at

nginx.com.

Thank you for using nginx.

浏览器访问都能显示nginx welcome界面

http://172.172.20.14:30457

http://172.172.20.15:30457

http://nodes:30457

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐