Kubernetes : Minikube : Deploy Pods
2015/12/13 |
[1] | Create or Delete Pods. |
# run 2 [test-nginx] pods [root@dlp ~]# kubectl run test-nginx --image=nginx --replicas=2 --port=80 deployment.apps "test-nginx" created kubectl get pods NAME READY STATUS RESTARTS AGE test-nginx-c8b797d7d-mzf9h 1/1 Running 0 25s test-nginx-c8b797d7d-zh78r 1/1 Running 0 25s # show environment variable for [test-nginx] pod [root@dlp ~]# kubectl exec test-nginx-c8b797d7d-mzf9h env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=test-nginx-c8b797d7d-mzf9h KUBERNETES_SERVICE_PORT_HTTPS=443 KUBERNETES_PORT=tcp://10.96.0.1:443 KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443 KUBERNETES_PORT_443_TCP_PROTO=tcp KUBERNETES_PORT_443_TCP_PORT=443 KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1 KUBERNETES_SERVICE_HOST=10.96.0.1 KUBERNETES_SERVICE_PORT=443 NGINX_VERSION=1.13.11-1~stretch NJS_VERSION=1.13.11.0.2.0-1~stretch HOME=/root # shell access to [test-nginx] pod [root@dlp ~]# kubectl exec -it test-nginx-c8b797d7d-mzf9h bash
hostname test-nginx-c8b797d7d-mzf9h root@test-nginx-c8b797d7d-mzf9h:/# curl localhost <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> ..... ..... <p><em>Thank you for using nginx.</em></p> </body> </html>
root@test-nginx-c8b797d7d-mzf9h:/#
exit
# show logs of [test-nginx] pod [root@dlp ~]# kubectl logs test-nginx-c8b797d7d-mzf9h 127.0.0.1 - - [09/Apr/2018:07:51:22 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.52.1" "-" # scale out pods [root@dlp ~]# kubectl scale deployment test-nginx --replicas=3 deployment.extensions "test-nginx" scaled [root@dlp ~]# kubectl get pods NAME READY STATUS RESTARTS AGE test-nginx-c8b797d7d-kdgmk 1/1 Running 0 7s test-nginx-c8b797d7d-mzf9h 1/1 Running 0 4m test-nginx-c8b797d7d-zh78r 1/1 Running 0 4m # set service [root@dlp ~]# kubectl expose deployment test-nginx --type="NodePort" --port 80 service "test-nginx" exposed [root@dlp ~]# kubectl get services test-nginx NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE test-nginx NodePort 10.99.186.171 <none> 80:31495/TCP 11s[root@dlp ~]# minikube service test-nginx --url http://192.168.39.110:31495 [root@dlp ~]# curl http://192.168.39.110:31495 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> ..... ..... <p><em>Thank you for using nginx.</em></p> </body> </html> # delete service [root@dlp ~]# kubectl delete services test-nginx service "test-nginx" deleted # delete pods [root@dlp ~]# kubectl delete deployment test-nginx deployment.extensions "test-nginx" deleted |