• Kubernetes实战(五)-pod之间网络请求实战


    1 同namespace内pod网络请求

    1.1 创建namespace ygq

    1. $ kubectl create namespace ygq
    2. namespace/ygq created

    1.2 创建svc和deployment 

    在naemspace ygq下创建两个应用:nginx和nginx-test。

    1.2.1 部署应用nginx

    1. $ cat nginx-svc.yaml
    2. apiVersion: v1
    3. kind: Service
    4. metadata:
    5. name: nginx
    6. namespace: ygq
    7. spec:
    8. selector:
    9. app: nginx
    10. ports:
    11. - port: 80
    12. type: ClusterIP
    1. $ cat deployment-nginx.yaml
    2. apiVersion: apps/v1
    3. kind: Deployment
    4. metadata:
    5. creationTimestamp: null
    6. labels:
    7. app: nginx
    8. name: nginx
    9. namespace: ygq
    10. spec:
    11. replicas: 1
    12. selector:
    13. matchLabels:
    14. app: nginx
    15. template:
    16. metadata:
    17. creationTimestamp: null
    18. labels:
    19. app: nginx
    20. spec:
    21. containers:
    22. - image: docker.io/library/nginx:latest
    23. name: nginx
    24. imagePullPolicy: IfNotPresent
    25. imagePullSecrets:
    26. - name: harbor-login
    1. $ kubectl apply -f nginx-svc.yaml
    2. $ kubectl apply -f deployment-nginx.yaml
    3. $ kubectl get svc -n ygq
    4. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
    5. nginx ClusterIP 192.168.245.168 <none> 80/TCP 3d
    6. $ kubectl get pod -n ygq
    7. NAME READY STATUS RESTARTS AGE
    8. nginx-547cc75cb7-j46zl 1/1 Running 0 2d22h

    1.2.2 部署应用nginx-test

    1. $ cat nginx-test-svc.yaml
    2. apiVersion: v1
    3. kind: Service
    4. metadata:
    5. name: nginx-test
    6. namespace: ygq
    7. spec:
    8. selector:
    9. app: nginx-test
    10. ports:
    11. - port: 80
    12. type: ClusterIP
    1. $ cat deployment-nginx-test.yaml
    2. apiVersion: apps/v1
    3. kind: Deployment
    4. metadata:
    5. creationTimestamp: null
    6. labels:
    7. app: nginx-test
    8. name: nginx-test
    9. namespace: ygq
    10. spec:
    11. replicas: 1
    12. selector:
    13. matchLabels:
    14. app: nginx-test
    15. template:
    16. metadata:
    17. creationTimestamp: null
    18. labels:
    19. app: nginx-test
    20. spec:
    21. containers:
    22. - image: docker.io/library/nginx:latest
    23. name: nginx
    24. imagePullPolicy: IfNotPresent
    25. imagePullSecrets:
    26. - name: harbor-login
    1. $ kubectl apply -f nginx-test-svc.yaml
    2. $ kubectl apply -f deployment-nginx-test.yaml
    3. $ kubectl get svc -n ygq
    4. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
    5. nginx-test ClusterIP 192.168.97.154 <none> 80/TCP 3d
    6. $ kubectl get pod -n ygq
    7. NAME READY STATUS RESTARTS AGE
    8. nginx-test-6c5f4dfc79-2ldhg 1/1 Running 1 (2d23h ago) 3d

    1.3 测试nginx与nginx-test互相访问

    1.3.1 nginx访问nginx-test

    1.3.1.1 登录nginx pod
    1. $ kubectl exec -it nginx-547cc75cb7-j46zl /bin/bash -n ygq
    2. kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
    1.3.1.2 svc name方式访问nginx-test
    1. root@nginx-547cc75cb7-j46zl:/# curl nginx
    2. <!DOCTYPE html>
    3. <html>
    4. <head>
    5. <title>Welcome to nginx!</title>
    6. <style>
    7. html { color-scheme: light dark; }
    8. body { width: 35em; margin: 0 auto;
    9. font-family: Tahoma, Verdana, Arial, sans-serif; }
    10. </style>
    11. </head>
    12. <body>
    13. <h1>Welcome to nginx!</h1>
    14. <p>If you see this page, the nginx web server is successfully installed and
    15. working. Further configuration is required.</p>
    16. <p>For online documentation and support please refer to
    17. <a href="http://nginx.org/">nginx.org</a>.<br/>
    18. Commercial support is available at
    19. <a href="http://nginx.com/">nginx.com</a>.</p>
    20. <p><em>Thank you for using nginx.</em></p>
    21. </body>
    22. </html>
    1.3.1.3 pod ip方式访问nginx-test
    1. # kubectl get pod -n ygq -o wide
    2. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
    3. nginx-test-6c5f4dfc79-2ldhg 1/1 Running 1 (2d23h ago) 3d 172.20.176.17 cn-shanghai.10.12.46.85 <none> <none>

    pod ip是172.20.176.17。

    1. root@nginx-547cc75cb7-j46zl:/# curl http://172.20.176.17:80
    2. <!DOCTYPE html>
    3. <html>
    4. <head>
    5. <title>Welcome to nginx!</title>
    6. <style>
    7. html { color-scheme: light dark; }
    8. body { width: 35em; margin: 0 auto;
    9. font-family: Tahoma, Verdana, Arial, sans-serif; }
    10. </style>
    11. </head>
    12. <body>
    13. <h1>Welcome to nginx!</h1>
    14. <p>If you see this page, the nginx web server is successfully installed and
    15. working. Further configuration is required.</p>
    16. <p>For online documentation and support please refer to
    17. <a href="http://nginx.org/">nginx.org</a>.<br/>
    18. Commercial support is available at
    19. <a href="http://nginx.com/">nginx.com</a>.</p>
    20. <p><em>Thank you for using nginx.</em></p>
    21. </body>
    22. </html>
    1.3.1.4 dns方式访问

    k8s 中dns的组成结构为:service_name.namespace_name.svc.cluster.local:port,可简写为service_name.namespace_name.svc:port。

    deployment nginx-test的端口为80,其dns为:nginx-test.ygq.svc.cluster.local:80,简写为:nginx-test.ygq.svc:80。

    1)完整dns

    1. root@nginx-547cc75cb7-j46zl:/# curl http://nginx-test.ygq.svc.cluster.local:80
    2. <!DOCTYPE html>
    3. <html>
    4. <head>
    5. <title>Welcome to nginx!</title>
    6. <style>
    7. html { color-scheme: light dark; }
    8. body { width: 35em; margin: 0 auto;
    9. font-family: Tahoma, Verdana, Arial, sans-serif; }
    10. </style>
    11. </head>
    12. <body>
    13. <h1>Welcome to nginx!</h1>
    14. <p>If you see this page, the nginx web server is successfully installed and
    15. working. Further configuration is required.</p>
    16. <p>For online documentation and support please refer to
    17. <a href="http://nginx.org/">nginx.org</a>.<br/>
    18. Commercial support is available at
    19. <a href="http://nginx.com/">nginx.com</a>.</p>
    20. <p><em>Thank you for using nginx.</em></p>
    21. </body>
    22. </html>

    2)简写dns

    1. root@nginx-547cc75cb7-j46zl:/# curl http://nginx-test.ygq.svc:80
    2. <!DOCTYPE html>
    3. <html>
    4. <head>
    5. <title>Welcome to nginx!</title>
    6. <style>
    7. html { color-scheme: light dark; }
    8. body { width: 35em; margin: 0 auto;
    9. font-family: Tahoma, Verdana, Arial, sans-serif; }
    10. </style>
    11. </head>
    12. <body>
    13. <h1>Welcome to nginx!</h1>
    14. <p>If you see this page, the nginx web server is successfully installed and
    15. working. Further configuration is required.</p>
    16. <p>For online documentation and support please refer to
    17. <a href="http://nginx.org/">nginx.org</a>.<br/>
    18. Commercial support is available at
    19. <a href="http://nginx.com/">nginx.com</a>.</p>
    20. <p><em>Thank you for using nginx.</em></p>
    21. </body>
    22. </html>

    1.3.2  nginx-test访问nginx

    1.3.2.1 登录nginx-test pod
    1. $ kubectl exec -it nginx-test-6c5f4dfc79-2ldhg /bin/bash -n ygq
    2. kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
    1.3.2.2 svc name方式访问nginx
    1. root@nginx-test-6c5f4dfc79-2ldhg:/# curl nginx
    2. <!DOCTYPE html>
    3. <html>
    4. <head>
    5. <title>Welcome to nginx!</title>
    6. <style>
    7. html { color-scheme: light dark; }
    8. body { width: 35em; margin: 0 auto;
    9. font-family: Tahoma, Verdana, Arial, sans-serif; }
    10. </style>
    11. </head>
    12. <body>
    13. <h1>Welcome to nginx!</h1>
    14. <p>If you see this page, the nginx web server is successfully installed and
    15. working. Further configuration is required.</p>
    16. <p>For online documentation and support please refer to
    17. <a href="http://nginx.org/">nginx.org</a>.<br/>
    18. Commercial support is available at
    19. <a href="http://nginx.com/">nginx.com</a>.</p>
    20. <p><em>Thank you for using nginx.</em></p>
    21. </body>
    22. </html>
    1.3.2.3 pod ip方式访问nginx
    1. $ kubectl get pod -n ygq -o wide
    2. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
    3. nginx-547cc75cb7-j46zl 1/1 Running 0 2d23h 172.20.176.24 cn-shanghai.10.12.46.85 <none> <none>
    1. root@nginx-test-6c5f4dfc79-2ldhg:/# curl http://172.20.176.24:80
    2. <!DOCTYPE html>
    3. <html>
    4. <head>
    5. <title>Welcome to nginx!</title>
    6. <style>
    7. html { color-scheme: light dark; }
    8. body { width: 35em; margin: 0 auto;
    9. font-family: Tahoma, Verdana, Arial, sans-serif; }
    10. </style>
    11. </head>
    12. <body>
    13. <h1>Welcome to nginx!</h1>
    14. <p>If you see this page, the nginx web server is successfully installed and
    15. working. Further configuration is required.</p>
    16. <p>For online documentation and support please refer to
    17. <a href="http://nginx.org/">nginx.org</a>.<br/>
    18. Commercial support is available at
    19. <a href="http://nginx.com/">nginx.com</a>.</p>
    20. <p><em>Thank you for using nginx.</em></p>
    21. </body>
    22. </html>
    1.3.2.4 dns方式访问

    deployment nginx的端口为80,其dns为:nginx.ygq.svc.cluster.local:80,简写为:nginx.ygq.svc:80。

    1)完整dns

    1. root@nginx-test-6c5f4dfc79-2ldhg:/# curl nginx.ygq.svc.cluster.local:80
    2. <!DOCTYPE html>
    3. <html>
    4. <head>
    5. <title>Welcome to nginx!</title>
    6. <style>
    7. html { color-scheme: light dark; }
    8. body { width: 35em; margin: 0 auto;
    9. font-family: Tahoma, Verdana, Arial, sans-serif; }
    10. </style>
    11. </head>
    12. <body>
    13. <h1>Welcome to nginx!</h1>
    14. <p>If you see this page, the nginx web server is successfully installed and
    15. working. Further configuration is required.</p>
    16. <p>For online documentation and support please refer to
    17. <a href="http://nginx.org/">nginx.org</a>.<br/>
    18. Commercial support is available at
    19. <a href="http://nginx.com/">nginx.com</a>.</p>
    20. <p><em>Thank you for using nginx.</em></p>
    21. </body>
    22. </html>

    2)简写dns

    1. root@nginx-test-6c5f4dfc79-2ldhg:/# curl nginx.ygq.svc:80
    2. <!DOCTYPE html>
    3. <html>
    4. <head>
    5. <title>Welcome to nginx!</title>
    6. <style>
    7. html { color-scheme: light dark; }
    8. body { width: 35em; margin: 0 auto;
    9. font-family: Tahoma, Verdana, Arial, sans-serif; }
    10. </style>
    11. </head>
    12. <body>
    13. <h1>Welcome to nginx!</h1>
    14. <p>If you see this page, the nginx web server is successfully installed and
    15. working. Further configuration is required.</p>
    16. <p>For online documentation and support please refer to
    17. <a href="http://nginx.org/">nginx.org</a>.<br/>
    18. Commercial support is available at
    19. <a href="http://nginx.com/">nginx.com</a>.</p>
    20. <p><em>Thank you for using nginx.</em></p>
    21. </body>
    22. </html>

    1.4 结论

    同namespace下不同pod直接可通过svc name、pod ip及dns互相访问。

    pod ip是不固定的,会伴随pod的状态变化发生改变,生产环境不建议使用pod ip作为请求地址。 

    2 不同namespace间pod网络请求

    2.1 创建namespace dev

    1. $ kubectl create namespace dev
    2. namespace/dev created

    2.2 创建svc和deployment 

    在naemspace dev下创建应用:nginx-dev。

    2.2.1 部署应用nginx-dev

    1. $ cat deployment-nginx-dev.yaml
    2. apiVersion: apps/v1
    3. kind: Deployment
    4. metadata:
    5. creationTimestamp: null
    6. labels:
    7. app: nginx-dev
    8. name: nginx-dev
    9. namespace: dev
    10. spec:
    11. replicas: 4
    12. selector:
    13. matchLabels:
    14. app: nginx-dev
    15. template:
    16. metadata:
    17. creationTimestamp: null
    18. labels:
    19. app: nginx-dev
    20. spec:
    21. containers:
    22. - image: docker.io/library/nginx:latest
    23. name: nginx
    24. imagePullPolicy: IfNotPresent
    25. imagePullSecrets:
    26. - name: harbor-login
    1. $ cat nginx-dev-svc.yaml
    2. apiVersion: v1
    3. kind: Service
    4. metadata:
    5. name: nginx-dev
    6. namespace: dev
    7. spec:
    8. selector:
    9. app: nginx-dev
    10. ports:
    11. - port: 80
    12. type: ClusterIP
    1. $ kubectl apply -f nginx-dev-svc.yaml
    2. $ kubectl apply -f deployment-nginx-dev.yaml
    3. # kubectl get svc -n dev
    4. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
    5. nginx-dev ClusterIP 192.168.28.113 <none> 80/TCP 3d
    6. $ kubectl get pod -n dev
    7. NAME READY STATUS RESTARTS AGE
    8. nginx-dev-5966c9747d-gbdq4 1/1 Running 1 (3d ago) 3d

    2.3 测试nginx与nginx-dev互相访问

    2.3.1 nginx访问nginx-dev

    2.3.1.1 登录nginx pod
    1. $ kubectl exec -it nginx-547cc75cb7-j46zl /bin/bash -n ygq
    2. kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
    2.3.1.2 svc name方式访问
    1. root@nginx-547cc75cb7-j46zl:/# curl nginx-dev
    2. curl: (6) Could not resolve host: nginx-dev
    2.3.1.3 pod ip方式访问 
    1. $ kubectl get pod -n dev -o wide
    2. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
    3. nginx-dev-5966c9747d-gbdq4 1/1 Running 1 (3d ago) 3d 172.20.176.9 cn-shanghai.10.12.46.85 <none> <none>
    1. root@nginx-547cc75cb7-j46zl:/# curl 172.20.176.9:80
    2. <!DOCTYPE html>
    3. <html>
    4. <head>
    5. <title>Welcome to nginx!</title>
    6. <style>
    7. html { color-scheme: light dark; }
    8. body { width: 35em; margin: 0 auto;
    9. font-family: Tahoma, Verdana, Arial, sans-serif; }
    10. </style>
    11. </head>
    12. <body>
    13. <h1>Welcome to nginx!</h1>
    14. <p>If you see this page, the nginx web server is successfully installed and
    15. working. Further configuration is required.</p>
    16. <p>For online documentation and support please refer to
    17. <a href="http://nginx.org/">nginx.org</a>.<br/>
    18. Commercial support is available at
    19. <a href="http://nginx.com/">nginx.com</a>.</p>
    20. <p><em>Thank you for using nginx.</em></p>
    21. </body>
    22. </html>
    2.3.1.4 dns方式访问

    deployment nginx-dev的端口为80,其dns为:nginx-dev.dev.svc.cluster.local:80,简写为:nginx-dev.dev.svc:80。

    1)完整dns

    1. root@nginx-547cc75cb7-j46zl:/# curl nginx-dev.dev.svc.cluster.local:80
    2. <!DOCTYPE html>
    3. <html>
    4. <head>
    5. <title>Welcome to nginx!</title>
    6. <style>
    7. html { color-scheme: light dark; }
    8. body { width: 35em; margin: 0 auto;
    9. font-family: Tahoma, Verdana, Arial, sans-serif; }
    10. </style>
    11. </head>
    12. <body>
    13. <h1>Welcome to nginx!</h1>
    14. <p>If you see this page, the nginx web server is successfully installed and
    15. working. Further configuration is required.</p>
    16. <p>For online documentation and support please refer to
    17. <a href="http://nginx.org/">nginx.org</a>.<br/>
    18. Commercial support is available at
    19. <a href="http://nginx.com/">nginx.com</a>.</p>
    20. <p><em>Thank you for using nginx.</em></p>
    21. </body>
    22. </html>

    2)简写dns

    1. root@nginx-547cc75cb7-j46zl:/# curl nginx-dev.dev.svc:80
    2. <!DOCTYPE html>
    3. <html>
    4. <head>
    5. <title>Welcome to nginx!</title>
    6. <style>
    7. html { color-scheme: light dark; }
    8. body { width: 35em; margin: 0 auto;
    9. font-family: Tahoma, Verdana, Arial, sans-serif; }
    10. </style>
    11. </head>
    12. <body>
    13. <h1>Welcome to nginx!</h1>
    14. <p>If you see this page, the nginx web server is successfully installed and
    15. working. Further configuration is required.</p>
    16. <p>For online documentation and support please refer to
    17. <a href="http://nginx.org/">nginx.org</a>.<br/>
    18. Commercial support is available at
    19. <a href="http://nginx.com/">nginx.com</a>.</p>
    20. <p><em>Thank you for using nginx.</em></p>
    21. </body>
    22. </html>

    2.3.2 nginx-dev访问nginx

    2.3.2.1 登录nginx-dev pod
    1. $ kubectl exec -it nginx-dev-5966c9747d-gbdq4 /bin/bash -n dev
    2. kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
    2.3.2.2 svc name方式访问
    1. root@nginx-dev-5966c9747d-gbdq4:/# curl nginx
    2. curl: (6) Could not resolve host: nginx
    2.3.2.3 pod ip方式访问
    1. $ kubectl get pod -n ygq -o wide
    2. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
    3. nginx-547cc75cb7-j46zl 1/1 Running 0 2d23h 172.20.176.24 cn-shanghai.10.12.46.85 <none> <none>
    1. root@nginx-dev-5966c9747d-gbdq4:/# curl 172.20.176.24:80
    2. <!DOCTYPE html>
    3. <html>
    4. <head>
    5. <title>Welcome to nginx!</title>
    6. <style>
    7. html { color-scheme: light dark; }
    8. body { width: 35em; margin: 0 auto;
    9. font-family: Tahoma, Verdana, Arial, sans-serif; }
    10. </style>
    11. </head>
    12. <body>
    13. <h1>Welcome to nginx!</h1>
    14. <p>If you see this page, the nginx web server is successfully installed and
    15. working. Further configuration is required.</p>
    16. <p>For online documentation and support please refer to
    17. <a href="http://nginx.org/">nginx.org</a>.<br/>
    18. Commercial support is available at
    19. <a href="http://nginx.com/">nginx.com</a>.</p>
    20. <p><em>Thank you for using nginx.</em></p>
    21. </body>
    22. </html>
    2.3.2.4 dns方式访问

    deployment nginx的端口为80,其dns为:nginx.ygq.svc.cluster.local:80,简写为:nginx.ygq.svc:80。

    1)完整dns

    1. root@nginx-dev-5966c9747d-gbdq4:/# curl nginx.ygq.svc.cluster.local:80
    2. <!DOCTYPE html>
    3. <html>
    4. <head>
    5. <title>Welcome to nginx!</title>
    6. <style>
    7. html { color-scheme: light dark; }
    8. body { width: 35em; margin: 0 auto;
    9. font-family: Tahoma, Verdana, Arial, sans-serif; }
    10. </style>
    11. </head>
    12. <body>
    13. <h1>Welcome to nginx!</h1>
    14. <p>If you see this page, the nginx web server is successfully installed and
    15. working. Further configuration is required.</p>
    16. <p>For online documentation and support please refer to
    17. <a href="http://nginx.org/">nginx.org</a>.<br/>
    18. Commercial support is available at
    19. <a href="http://nginx.com/">nginx.com</a>.</p>
    20. <p><em>Thank you for using nginx.</em></p>
    21. </body>
    22. </html>

    2)简写dns

    1. root@nginx-dev-5966c9747d-gbdq4:/# curl nginx.ygq.svc:80
    2. <!DOCTYPE html>
    3. <html>
    4. <head>
    5. <title>Welcome to nginx!</title>
    6. <style>
    7. html { color-scheme: light dark; }
    8. body { width: 35em; margin: 0 auto;
    9. font-family: Tahoma, Verdana, Arial, sans-serif; }
    10. </style>
    11. </head>
    12. <body>
    13. <h1>Welcome to nginx!</h1>
    14. <p>If you see this page, the nginx web server is successfully installed and
    15. working. Further configuration is required.</p>
    16. <p>For online documentation and support please refer to
    17. <a href="http://nginx.org/">nginx.org</a>.<br/>
    18. Commercial support is available at
    19. <a href="http://nginx.com/">nginx.com</a>.</p>
    20. <p><em>Thank you for using nginx.</em></p>
    21. </body>
    22. </html>

    2.4 结论 

    不同namespace下pod直接可通过pod ip及dns互相访问,但不能通过svc name进行访问

    pod ip是不固定的,会伴随pod的状态变化发生改变,生产环境不建议使用pod ip作为请求地址。 

    3 pod name实战

    3.1 同一namespace下

    3.1.1 deployment

    1. $ kubectl get pod -n ygq -o wide
    2. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
    3. nginx-547cc75cb7-j46zl 1/1 Running 0 3d 172.20.176.24 cn-shanghai.10.12.46.85 <none> <none>
    4. nginx-test-6c5f4dfc79-2ldhg 1/1 Running 1 (3d ago) 3d2h 172.20.176.17 cn-shanghai.10.12.46.85 <none> <none>
    1. $ kubectl create -f deployment-nginx.yaml
    2. Error from server (AlreadyExists): error when creating "deployment-nginx.yaml": deployments.apps "nginx" already exists

    3.1.2 Service

    1. $ kubectl get svc -n ygq -o wide
    2. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
    3. nginx ClusterIP 192.168.245.168 <none> 80/TCP 3d1h app=nginx
    4. nginx-test ClusterIP 192.168.97.154 <none> 80/TCP 3d1h app=nginx-test
    1. $ kubectl create -f nginx-svc.yaml
    2. Error from server (AlreadyExists): error when creating "nginx-svc.yaml": services "nginx" already exists

    3.2 不同namespace 

    3.2.1 deployment

    1. $ kubectl get pod -n dev -o wide
    2. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
    3. nginx-cfcb57f6d-vr79r 1/1 Running 0 10s 172.20.176.28 cn-shanghai.10.12.46.85 <none> <none>
    4. nginx-dev-5966c9747d-gbdq4 1/1 Running 1 (3d1h ago) 3d1h 172.20.176.9 cn-shanghai.10.12.46.85 <none> <none>
    1. $ kubectl get pod -n ygq -o wide
    2. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
    3. nginx-547cc75cb7-j46zl 1/1 Running 0 3d 172.20.176.24 cn-shanghai.10.12.46.85 <none> <none>
    4. nginx-test-6c5f4dfc79-2ldhg 1/1 Running 1 (3d ago) 3d2h 172.20.176.17 cn-shanghai.10.12.46.85 <none> <none>

    3.2.2 Service 

    1. $ kubectl get svc -n dev -o wide
    2. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
    3. nginx ClusterIP 192.168.87.200 <none> 80/TCP 7s app=nginx
    4. nginx-dev ClusterIP 192.168.28.113 <none> 80/TCP 3d1h app=nginx-dev
    1. $ kubectl get svc -n ygq -o wide
    2. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
    3. nginx ClusterIP 192.168.245.168 <none> 80/TCP 3d1h app=nginx
    4. nginx-test ClusterIP 192.168.97.154 <none> 80/TCP 3d1h app=nginx-test

    3.3 结论

    不同namescpace下可以存在相同名称的资源,同一namespace下不允许有相同名称的资源。

    4 总结

    • 同一namespace下的应用可以通过svc name、pod ip和dns互相访问,不同namespace下可以通过pod ip和dns互相访问。
    • 同一namespace下不允许有相同名称的资源,不同namescpace下可以存在名字一样的资源。

     

     

     

     

  • 相关阅读:
    使用vuedraggable实现拖拽式操作实战
    如何在 Azure 容器应用程序上部署具有 Elastic Observability 的 Hello World Web 应用程序
    Linux进程管理和计划任务与系统备份恢复
    实用技巧,用lsof命令监控tar文件解压进度,简单有效!
    爬虫记录——第三方钱包加密参数逆向
    安防监控系统/视频云存储EasyCVR平台视频无法播放是什么原因?
    安装stable-diffusion
    pdf文件怎么转换成图片?
    B树(数据结构篇)
    IDEA离线安装插件
  • 原文地址:https://blog.csdn.net/ygq13572549874/article/details/134484604