# 在即有k8s cluster上部署web ## 1. 寫一deployment yaml ``` vi deployment-nginx.yaml ``` 內容: ``` apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx-sandy spec: replicas: 3 selector: matchLabels: app: nginx-sandy template: metadata: labels: app: nginx-sandy spec: containers: - name: nginx-sandy image: nginx:1.14.2 ports: - containerPort: 80 ``` ## 2. Apply yaml file ``` kubectl apply -f deployment-nginx.yaml ``` ``` kubectl get pods -A ``` ![](https://hackmd.io/_uploads/H1RN8bjI3.png) ## 3. expose ``` kubectl expose pod nginx-deployment-84dc78576-8g6kn --type="NodePort" --port 80 ``` ![](https://hackmd.io/_uploads/ByuTLZi83.png) ## 4. describe ``` kubectl describe svc nginx-deployment-84dc78576-8g6kn ``` ![](https://hackmd.io/_uploads/HklZSd-s8h.png) 它跑在 port 3192 ``` kubectl describe pod nginx-deployment-84dc78576-8g6kn ``` ![](https://hackmd.io/_uploads/H1_iu-oUh.png) 它跑在node : 172.22.41.168 ## 5. 測試網頁: ``` curl http://172.22.41.168:31926 ``` ## 6. 結果: ``` <!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> ``` ![](https://hackmd.io/_uploads/ryGGqZi8h.png)