Service

Headless, Endpoint, ExternalName
Service with Headless, Endpoint, ExternalName for Kubernetes.


Dns

Service with DNS Concept for Kubernetes.

Headless

Service with Headless Concept for Kubernetes.

External

Service with ExternalName Concept for Kubernetes.


Headless


Service with DNS Practice for Kubernetes.

1-1) Service

apiVersion: v1
kind: Service
metadata:
  name: clusterip1
spec:
  selector:
    svc: clusterip
  ports:
  - port: 80
    targetPort: 8080

1-2) Pod

apiVersion: v1
kind: Pod
metadata:
  name: pod1
  labels:
    svc: clusterip
spec:
  containers:
  - name: container
    image: kubetm/app

1-3) Request Pod

apiVersion: v1
kind: Pod
metadata:
  name: request-pod
spec:
  containers:
  - name: container
    image: kubetm/init
kubectl exec request-pod -it /bin/bash

nslookup

nslookup clusterip1
nslookup clusterip1.default.svc.cluster.local

curl

curl clusterip1/hostname
curl clusterip1.default.svc.cluster.local/hostname


Service with Headless Practice for Kubernetes.

2-1) Service

apiVersion: v1
kind: Service
metadata:
  name: headless1
spec:
  selector:
    svc: headless
  ports:
    - port: 80
      targetPort: 8080    
  clusterIP: None

2-2) Pod

apiVersion: v1
kind: Pod
metadata:
  name: pod4
  labels:
    svc: headless
spec:
  hostname: pod-a
  subdomain: headless1
  containers:
  - name: container
    image: kubetm/app

Nslookup

nslookup headless1
nslookup pod-a.headless1
nslookup pod-b.headless1

Curl

curl pod-a.headless1:8080/hostname
curl pod-b.headless1:8080/hostname


Endpoint


Service with Endpoint Practice1 for Kubernetes.

3-1) Service

apiVersion: v1
kind: Service
metadata:
  name: endpoint1
spec:
  selector:
    svc: endpoint
  ports:
  - port: 8080

3-2) Pod

apiVersion: v1
kind: Pod
metadata:
  name: pod7
  labels:
    svc: endpoint
spec:
  containers:
  - name: container
    image: kubetm/app
kubectl describe endpoints endpoint1


Service with Endpoint Practice2 for Kubernetes.

4-1) Service

apiVersion: v1
kind: Service
metadata:
  name: endpoint2
spec:
  ports:
  - port: 8080

4-2) Pod

apiVersion: v1
kind: Pod
metadata:
  name: pod9
spec:
  containers:
  - name: container
    image: kubetm/app

4-3) Endpoint

apiVersion: v1
kind: Endpoints
metadata:
  name: endpoint2
subsets:
 - addresses:
   - ip: 20.109.5.12
   ports:
   - port: 8080
curl endpoint2:8080/hostname


Service with Endpoint Practice3 for Kubernetes.

5-1) Service

apiVersion: v1
kind: Service
metadata:
  name: endpoint3
spec:
  ports:
  - port: 80

Github - Ip Address

nslookup https://www.github.com
curl -O 185.199.110.153:80/kubetm/kubetm.github.io/blob/master/sample/practice/intermediate/service-sample.md

5-2) Endpoint

apiVersion: v1
kind: Endpoints
metadata:
  name: endpoint3
subsets:
 - addresses:
   - ip: 185.199.110.153
   ports:
   - port: 80
curl -O endpoint3/kubetm/kubetm.github.io/blob/master/sample/practice/intermediate/service-sample.md


ExternalName


Service with ExternalName Practice for Kubernetes.

6-1) Service

apiVersion: v1
kind: Service
metadata:
 name: externalname1
spec:
 type: ExternalName
 externalName: github.github.io
curl -O externalname1/kubetm/kubetm.github.io/blob/master/sample/practice/intermediate/service-sample.md


yaml


Service

apiVersion: v1
kind: Service
metadata:
  name: headless1
spec:
  selector:             # 생략시 Endpoints 직접 생성해서 사용
    svc: headless
  ports:
    - port: 80
      targetPort: 8080    
  clusterIP: None       # headless 서비스  
  type: ExternalName    # ExternalName Service 설정시 사용
  externalName: github.github.io  # ExternalName사용시 연결 Domain지정

Endpoints

apiVersion: v1
kind: Endpoints
metadata:
  name: headless1       # Service의 이름과 동일하게 지정
subsets:
 - addresses:
   - ip: 20.109.5.12    # Pod의 ClusterIp
   ports:
   - port: 8080         # Pod의 Container Port

Pod

apiVersion: v1
kind: Pod
metadata:
  name: pod4
  labels:
    svc: headless
spec:
  hostname: pod-a       # 호스트네임 설정, 생략시 Pod Name이 적용됨
  subdomain: headless1  # headless 서비스 사용시 Service의 이름으로 지정
  containers:
  - name: container
    image: kubetm/app


kubectl


Exec

# Pod이름이 request-pod인 Container로 들어가기 (나올땐 exit)
kubectl exec request-pod -it /bin/bash

Describe

# Endpoints 상세보기
kubectl describe endpoints endpoint1


Tips


Dns

  • Kubernetes 버전 1.11 이전의 Kubernetes DNS 서비스는 kube-dns를 기반
  • 버전 1.11은 kube-dns의 일부 보안 및 안정성 문제를 해결하기 위해 CoreDNS 를 도입


Referenece


Kubernetes

Others