1
[root@k8s-master ~]# kubectl get pod -o wide --show-labels NAME READY STATUS RESTARTS AGE IP NODE LABELS nginx-65976c7ccb-9dspb 1/1 Running 0 1h 172.17.69.4 192.168.56.11 pod-template-hash=2153273776,run=nginx nginx-65976c7ccb-tgjm9 1/1 Running 0 1h 172.17.69.5 192.168.56.11 pod-template-hash=2153273776,run=nginx nginx-65976c7ccb-wc878 1/1 Running 1 6d 172.17.69.3 192.168.56.11 pod-template-hash=2153273776,run=nginx nginx-pod 1/1 Running 1 57m 172.17.52.2 192.168.56.12 app=nginx ##此处 [root@k8s-master ~]# kubectl create -f nginx-service.yaml service "my-service" created [root@k8s-master ~]# kubectl get service -o wide NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR kubernetes ClusterIP 10.10.10.1 <none> 443/TCP 7d <none> my-service ClusterIP 10.10.10.120 <none> 80/TCP,443/TCP 8s app=nginx #此处 nginx-service NodePort 10.10.10.84 <none> 88:36741/TCP 6d run=nginx [root@k8s-master ~]# kubectl get ep NAME ENDPOINTS AGE kubernetes 192.168.56.10:6443 7d my-service 172.17.52.2:443,172.17.52.2:443 16s #此处 nginx-service 172.17.69.3:80,172.17.69.4:80,172.17.69.5:80 6d
[root@k8s-master ~]#
apiVersion: v1 kind: Service metadata: name: my-service spec: selector: app: nginx ports: - name: http protocol: TCP port: 80 targetPort: 443 - name: https protocol: TCP port: 443 targetPort: 443