Cloud/Kubernetes

Selector가 없는 Service

퐁스 2021. 3. 3. 17:29

1. Service는 Endpoints를 갖는다.

[root@master ~]# kubectl get endpoints -n monitoring
NAME                    ENDPOINTS                                                               AGE
prometheus-k8s          10.244.104.226:9090,10.244.87.210:9090                                  119d

[root@ymaster ~]# kubectl get svc -n monitoring
prometheus-k8s          NodePort    10.96.240.250   <none>        9090:31425/TCP               119d

[root@ymaster ~]# kubectl get pods -n monitoring -o wide
NAME                                   READY   STATUS    RESTARTS   AGE    IP               
prometheus-k8s-0                       3/3     Running   0          10h    10.244.87.210 
prometheus-k8s-1                       3/3     Running   0          3d     10.244.104.22

2. Selector 없는 Service도 존재한다.

selector가 없어도 endpoints가 있으면 수동으로 매핑해준다.

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376

 

apiVersion: v1
kind: Endpoints
metadata:
  name: my-service
subsets:
  - addresses:
      - ip: 192.0.2.42
    ports:
      - port: 9376