# 在node2节点可以看到运行的mynginx和nginx镜像 [root@k8snode2 ~]# docker ps |grep mynginx 8596f8e18360 nginx "/docker-entrypoint.…" 3 minutes ago Up 3 minutes k8s_mynginx_mynginx_default_e3a3add5-2a0a-4af4-bcdb-719e8c1ff231_0 774584bc088f registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/pause:3.2 "/pause" 4 minutes ago Up 4 minutes k8s_POD_mynginx_default_e3a3add5-2a0a-4af4-bcdb-719e8c1ff231_0 [root@k8snode2 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest ea335eea17ab 11 days ago 141MB
# 查看Pod的运行日志 kubectl logs Pod名字 # 每个Pod - k8s都会分配一个ip kubectl get pod -owide # 使用Pod的ip+pod里面运行容器的端口 curl 192.168.169.136 [root@k8smaster ~]# kubectl get pods -owide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES mynginx 1/1 Running 0 21m 11.168.185.196 k8snode2 <none> <none> [root@k8smaster ~]# curl 11.168.185.196 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } 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> [root@k8smaster ~]# kubectl logs -f mynginx 2021/11/28 12:54:19 [notice] 1#1: start worker process 38 2021/11/28 12:54:19 [notice] 1#1: start worker process 39 11.168.16.128 - - [28/Nov/2021:13:14:56 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.29.0" "-"
# 如何进入到mynginx容器 [root@k8smaster ~]# kubectl get pods NAME READY STATUS RESTARTS AGE mynginx 1/1 Running 0 15m [root@k8smaster ~]# kubectl exec -it mynginx -- /bin/bash root@mynginx:/# cd /usr/share/nginx/html/ root@mynginx:/usr/share/nginx/html# ls 50x.html index.html root@mynginx:/usr/share/nginx/html# echo "hello tang"->index.html root@mynginx:/usr/share/nginx/html#
[root@k8smaster ~]# kubectl get pod mynginx -owide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES mynginx 1/1 Running 0 16m 11.168.185.197 k8snode2 <none> <none> [root@k8smaster ~]# curl 11.168.185.197 hello tang-
③. yaml文件的形式创建pod
apiVersion: v1 kind: Pod metadata: labels: run: mynginx name: mynginx # namespace: default spec: containers: - image: nginx name: mynginx
④. 使用图形化界面创建pod