创建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: <none>
Selector: run=load-balancer-example
Type: NodePort
IP: 10.105.170.116
Port: <unset> 80/TCP
NodePort: <unset> 30457/TCP
Endpoints: 10.244.3.14:80,10.244.5.6:80
Session Affinity: None
Events: <none>
测试nginx服务
[root@node1 yaml]# curl 10.105.170.116:80
<!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>nginx.org</a>.<br/>
Commercial support is available at
<a>nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
浏览器访问都能显示nginx welcome界面
http://172.172.20.14:30457
http://172.172.20.15:30457
http://nodes:30457