Net Eng

[CKA] - NodePort 서비스 생성 본문

Cloud/Kubernetes

[CKA] - NodePort 서비스 생성

欲心 2024. 1. 22. 10:34

[선수 작업]

kubectl config set-context k8s --user=kubernetes-admin --cluster=kubernetes
kubectl apply -f - <<EOF
kind: Deployment
apiVersion: apps/v1
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: webui
  replicas: 2
  template:
    metadata:
      labels:
        app: webui    
    spec:
      containers:
      - name: web-container
        image: nginx
        ports:
        - containerPort: 80
EOF

 


 

[문제]

Create the service as type NodePort with the port 32767 for the nginx pod with the pod selector app: webui.

 

작업 클러스터: k8s

 


 

[풀이]

kubectl config use-context k8s

* k8s 클러스터 사용

 

kubectl get pods -l app=webui --show-labels

* app:webui 레이블을 가진 Pod 확인

 

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app: webui
  ports:
    - port: 80
      targetPort: 80
      nodePort: 32767

* yaml 파일 생성

 

kubectl apply -f myservice.yaml

* yaml 파일 실행

 

curl node01:32767

* 실행 확인

 

지정한 포트로 접근하여 확인

 


[참고]

 

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

 

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

[CKA] - Secret 운영  (0) 2024.01.22
[CKA] - ConfigMap 운영  (1) 2024.01.22
[CKA] - Init Container를 포함한 Pod 운영  (1) 2024.01.22
[CKA] - CPU 사용량이 높은 파드 검색  (1) 2024.01.21
[CKA] - Pod Log 추출  (0) 2024.01.21