部署应用程序到kubernetes集群

第一步:在master 节点上创建一个deployment

# kubectl create deployment nginx --image=nginx deployment.apps/nginx created

检查执行效果,可以看到一个叫nginx的deployment创建成功了

# kubectl get deployments NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE nginx     1         1         1            1           1m

第二步:创建一个service,并暴露80端口

kubectl create service nodeport nginx --tcp 80:80

检查执行效果,可以看到一个叫nginx的service创建成功了,这里kubectl get svc是kubectl get services的简写

# kubectl create service nodeport nginx --tcp 80:80 service/nginx created

# kubectl get svc NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP        1d nginx        NodePort    10.96.248.169    <none>        80:31088/TCP   11s

执行下面的命令验证一下nginx有没有部署成功(顺带测试下容器间网络通信)

# curl 10.96.248.169 <!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>

清理现场

# kubectl delete deployments/nginx services/nginx deployment.extensions "nginx" deleted service "nginx" deleted

发表评论