Net Eng

[CKA] - Deployment & Expose the Service 본문

Cloud/Kubernetes

[CKA] - Deployment & Expose the Service

欲心 2024. 1. 21. 10:34

[선수 지식]

Deployment(ReplicaSet(Pod x N))

Service
* ClusterIP
* NodePort
* Loadbalancer
* ExternalName
+
* Headless Service => [참고] ExternalName(CNAME record) vs Headless Service(A record)
* Ingress          => [참고] Loadbalancer vs Ingress

 


 

[선수 작업]

kubectl config set-context k8s --user=kubernetes-admin --cluster=kubernetes
kubectl apply -f - <<EOF
kind: Deployment
apiVersion: apps/v1
metadata:
  name: front-end
spec:
  selector:
    matchLabels:
      run: nginx
  replicas: 2
  template:
    metadata:
      labels:
        run: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
EOF

 


 

[문제]

Reconfigure the existing deployment front-end and add a port specification named http exposing port 80/tcp of the existing container nginx. Create a new service named front-end-svc exposing the container port http. Configure the new service to also expose the individual Pods via a NodePort on the nodes on which they are scheduled.

 

작업 클러스터: k8s

 


 

[풀이]

kubectl config use-context k8s

* k8s 클러스터 사용

 

kubectl get deploy front-end -o yaml > front-end.yaml

* 실행중인 front-end deployment를 yaml 파일로 추출

 

apiVersion: apps/v1
kind: Deployment
metadata:
  name: front-end
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      run: nginx
  template:
    metadata:
      labels:
        run: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
          - containerPort: 80
            name: http

---
apiVersion: v1
kind: Service
metadata:
  name: front-end-svc
spec:
  type: NodePort
  selector:
    run: nginx
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: http

* yaml 파일 수정

 

kubectl delete deploy front-end

* 기존 실행중인 deployment 제거

 

kubectl apply -f front-end.yaml

* yaml 파일 실행

 

kubectl get svc

* 실행중인 service 확인

 

curl node01:*****

* 포트번호 입력하여 확인

 

nginx 실행 확인

 


 

[참고]

 

서비스

외부와 접하는 단일 엔드포인트 뒤에 있는 클러스터에서 실행되는 애플리케이션을 노출시키며, 이는 워크로드가 여러 백엔드로 나뉘어 있는 경우에도 가능하다.

kubernetes.io

 

'Cloud > Kubernetes' 카테고리의 다른 글

[CKA] - CPU 사용량이 높은 파드 검색  (1) 2024.01.21
[CKA] - Pod Log 추출  (0) 2024.01.21
[CKA] - Node 정보 수집  (0) 2024.01.21
[CKA] - Node 관리  (0) 2024.01.21
[CKA] - Node Labels & nodeSelector  (0) 2024.01.21