1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
| Pod是k8s调度的最小单位,一个Pod中可以有多个Container 1、创建一个Pod yujiangdeMBP-13:k8s_yaml yujiang$ cat pod_nginx.yml apiVersion: v1 kind: Pod metadata: name: nginx labels: app: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80
yujiangdeMBP-13:k8s_yaml yujiang$ kubectl create -f pod_nginx.yml pod/nginx created
2、查看Pod yujiangdeMBP-13:k8s_yaml yujiang$ kubectl get pod --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE default nginx 1/1 Running 0 20m kube-system kube-addon-manager-minikube 1/1 Running 8 60m kube-system kube-dns-54cccfbdf8-kr847 3/3 Running 12 57m kube-system kubernetes-dashboard-77d8b98585-vq77b 1/1 Running 4 57m kube-system storage-provisioner 1/1 Running 5 57m
3、查看Pod的详细信息,可以看到Pod运行在哪台机器上 yujiangdeMBP-13:k8s_yaml yujiang$ kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx 1/1 Running 0 31m 172.17.0.2 minikube <none> <none>
4、打开dashboard yujiangdeMBP-13:k8s_yaml yujiang$ minikube dashboard
5、查询nginx IP $ docker network ls NETWORK ID NAME DRIVER SCOPE fb08befd952b bridge bridge local 2de0a434731f host host local 4cd7f4c7083c none null local
$ docker network inspect bridge [ { "Name": "bridge", "Id": "fb08befd952b4448e86e491f271a1e6a50056b5a18bdfb8a3e930edde2ac44da", "Created": "2018-12-24T17:23:11.618994916Z", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.17.0.0/16", "Gateway": "172.17.0.1" } ] }, "Internal": false, "Attachable": false, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, "Containers": { "25e63a3ff8a091319fdec698f554f1b47c3e019fbdda9b06709d15630003ee6e": { "Name": "k8s_POD_kube-dns-54cccfbdf8-kr847_kube-system_69d32f1a-0799-11e9-be08-080027bea66e_8", "EndpointID": "004b9a81ab36cd4e0aba21572b4736b8d85d5541c3533571a67383e5d07e34b6", "MacAddress": "02:42:ac:11:00:03", "IPv4Address": "172.17.0.3/16", "IPv6Address": "" }, "4138eeb8348781495987d47f6683138515111d2b6afa6fc7352d5f98d4a0858b": { "Name": "k8s_POD_kubernetes-dashboard-77d8b98585-vq77b_kube-system_69b46ed4-0799-11e9-be08-080027bea66e_8", "EndpointID": "bb31db755c5a5cd8f36bec35d89c73267d3d283ba8caa691b58ba504b0d6fabc", "MacAddress": "02:42:ac:11:00:04", "IPv4Address": "172.17.0.4/16", "IPv6Address": "" }, "6874ee85f9257b5b0dfdf808ebf92df9c3c677079a778980956e4655abf23507": { "Name": "k8s_POD_nginx_default_9e0d9ffc-079e-11e9-be08-080027bea66e_0", "EndpointID": "040a5616a76665ff9e35bb6cef2388f8db443b2db94b67282a7496b9803acc20", "MacAddress": "02:42:ac:11:00:02", "IPv4Address": "172.17.0.2/16", "IPv6Address": "" } }, "Options": { "com.docker.network.bridge.default_bridge": "true", "com.docker.network.bridge.enable_icc": "true", "com.docker.network.bridge.enable_ip_masquerade": "true", "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", "com.docker.network.bridge.name": "docker0", "com.docker.network.driver.mtu": "1500" }, "Labels": {} } ]
$ curl 172.17.0.2 <!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>
6、指定Pod名,进入Container(默认进入第1个Container)。如果Pod中有多个Container,可以加"-c"参数指定进入哪个Container。 yujiangdeMBP-13:k8s_yaml yujiang$ kubectl exec -it nginx sh
7、打印nginx Pod的详细信息 yujiangdeMBP-13:k8s_yaml yujiang$ kubectl describe pod nginx
8、怎样把nginx的端口映射出来? 有两种方法: (1)port-forward yujiangdeMBP-13:k8s_yaml yujiang$ kubectl port-forward nginx 8080:80 打开浏览器:http://127.0.0.1:8080/
|