티스토리 뷰
service : 쿠버네티스 외부에서 쿠버네티스 클러스터에 접속하는 방법
NodePort : 모든 워커 노드의 특정 포트를 열고, 해당 포트로의 요청을 노드 포트 서비스로 전달한다. 노드 포트 서비스는 해당 요청을 처리할 수 있는 파드로 요청을 전달한다. 파드는 요청에 대한 응답을 전송한다.
ref : https://zesty.co/finops-glossary/nodeport-in-kubernetes-a-glossary-overview/
What Is NodePort in Kubernetes? Everything You Need to Know
NodePort Services in Kubernetes expose apps externally, their port range, best use cases, differences from LoadBalancer and ClusterIP.
zesty.co
NodePort로 서비스 테스트
1. 간단한 이미지에 대한 파드를 배포
kubectl create deployment np-pods --image=sysnet4admin/echo-hname
2. NodePort 서비스 생성
nodeport.yaml
apiVersion: v1
kind: Service
metadata:
name: np-svc
spec:
selector:
app: np-pods
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
nodePort: 30000
type: NodePort
nodePort : 외부에서 클러스터로 접근하기 위한 port
port : 클러스터 내부에서 해당 서비스를 호출하는 port
targetPort : pod 내부의 애플리케이션이 리스닝하고 있는 port
서비스 생성
kubectl create -f nodeport.yaml
생성된 서비스 확인
➜ pod-yaml ✗ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 11d
np-svc NodePort 10.96.39.51 <none> 80:30000/TCP 38s
30000번 포트로의 요청을 np-svc 서비스 포트(port)인 80으로 전달
3. pod 애플리케이션에 요청
(현재 환경이 docker-desktop을 이용한 k8s 환경이므로, worker로 동작 중인 docker container 내부 ip 대신 127.0.0.1로 접속)
(30000번 port 요청을 해당 서비스 호출 port인 80으로 먼저 포트 포워딩 필요)
kubectl port-forward service/np-svc 30000:80

'메모 > kubernetes' 카테고리의 다른 글
CI/CD 개념 (0) | 2025.04.10 |
---|---|
docker desktop으로 멀티 노드 쿠버네티스 클러스터 구성하기 (0) | 2025.03.22 |
쿠버네티스 파드 관련 기본 명령어 (0) | 2025.03.22 |
kubetctl, kubelet 기능 검증 테스트 (0) | 2025.03.08 |
쿠버네티스 주요 구성 요소 (파드 배포 중심) (0) | 2025.02.28 |