티스토리 뷰

문제

작업 클러스터 : kubectl config use-context k8s
  • 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

 

문제 환경 구성

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: front-end
  name: front-end
spec:
  replicas: 2
  selector:
    matchLabels:
      run: nginx
  template:
    metadata:
      labels:
        run: nginx
    spec:
      containers:
      - image: nginx
        name: nginx

문제 풀이

# 1. 작업 클러스터 context 변경

kubectl config use-context k8s



# 2. front-end deployment yaml 추출하기

kubectl get deployments.apps front-end -o yaml > front-end.yaml



# 3. front-end.yaml 수정

vim front-end.yaml

....

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: front-end
  name: front-end
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: nginx-service-port
    protocol: TCP
    port: 80
    targetPort: http



# 4. 기존 deployment 삭제 및 변경 리소스 적용

kubectl delete deployments.apps front-end



# 5. 적용 확인

kubectl get svc front-end-svc

curl <노드 ip>:<노드 port>
 

Service

Expose an application running in your cluster behind a single outward-facing endpoint, even when the workload is split across multiple backends.

kubernetes.io

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/09   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함