Linux入门教程:Kubernetes(k8s)部署并测试nginx service,k8snginx

创建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      node5
default       nginx-3431010723-bw22q                  1/1       Running   2          1h     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
Port:            <unset>    80/TCP
NodePort:        <unset>    30457/TCP
Session Affinity:    None
Events:            <none>


[root@node1 yaml]# curl
<!DOCTYPE html>
<title>Welcome to nginx!</title>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
<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=""></a>.<br/>
Commercial support is available at
<a href=""></a>.</p>

<p><em>Thank you for using nginx.</em></p>

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