k8s service

master:192.168.59.100
node1:192.168.59.101
kubectl edit svc services-readiness-demo

apiVersion: v1
kind: Service
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"services-readiness-demo","namespace":"default"},"spec":{"ports":[{"name":"http","port":80,"protocol":"TCP","targetPort":80}],"selector":{"app":"demoapp-with-readiness"}}}
  creationTimestamp: "2023-04-10T09:19:52Z"
  name: services-readiness-demo
  namespace: default
  resourceVersion: "279443"
  uid: b35565aa-5c1d-4be7-9666-97cf9a77ca31
spec:
  clusterIP: 10.105.247.115
  clusterIPs:
  - 10.105.247.115
  externalIPs:
  - 192.168.59.101
  externalTrafficPolicy: Cluster
  internalTrafficPolicy: Cluster
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - name: http
    nodePort: 30749
    port: 8000
    protocol: TCP
    targetPort: 80
  selector:
    app: demoapp-with-readiness
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}

[root@master ~]# kubectl get svc -o wide
NAME                      TYPE        CLUSTER-IP       EXTERNAL-IP      PORT(S)          AGE     SELECTOR
services-readiness-demo   NodePort    10.105.247.115   192.168.59.101   8000:30749/TCP   7d22h   app=demoapp-with-readiness

本地:

[root@master ~]# curl localhost:30749
iKubernetes demoapp v1.0 !! ClientIP: 10.244.219.64, ServerName: demoapp2-768d78949d-vjvpx, ServerIP: 10.244.166.146!
[root@master ~]#
[root@master ~]# curl 10.105.247.115:8000
iKubernetes demoapp v1.0 !! ClientIP: 10.244.219.64, ServerName: demoapp2-768d78949d-vjvpx, ServerIP: 10.244.166.146!
[root@master ~]#
[root@master ~]# curl 192.168.59.101:8000
iKubernetes demoapp v1.0 !! ClientIP: 10.244.219.64, ServerName: demoapp2-768d78949d-crshr, ServerIP: 10.244.166.144!

容器内部:

[root@demoapp2-768d78949d-crshr /]# curl services-readiness-demo:8000
iKubernetes demoapp v1.0 !! ClientIP: 10.244.166.144, ServerName: demoapp2-768d78949d-vjvpx, ServerIP: 10.244.166.146!
[root@demoapp2-768d78949d-crshr /]#
[root@demoapp2-768d78949d-crshr /]# curl services-readiness-demo.default.svc.cluster.local.:8000
iKubernetes demoapp v1.0 !! ClientIP: 192.168.59.101, ServerName: demoapp2-768d78949d-crshr, ServerIP: 10.244.166.144!
[root@demoapp2-768d78949d-crshr /]#
[root@demoapp2-768d78949d-crshr /]# curl 192.168.59.101:8000
iKubernetes demoapp v1.0 !! ClientIP: 10.244.166.144, ServerName: demoapp2-768d78949d-vjvpx, ServerIP: 10.244.166.146!
[root@demoapp2-768d78949d-crshr /]#
[root@demoapp2-768d78949d-crshr /]#
[root@demoapp2-768d78949d-crshr /]# curl 10.105.247.115:8000
iKubernetes demoapp v1.0 !! ClientIP: 10.244.166.144, ServerName: demoapp2-768d78949d-vjvpx, ServerIP: 10.244.166.146!

你可能感兴趣的:(kubernetes,容器,云原生)