본문 바로가기
INFRA/DevOps

[k8s] NodePort

by BTC_비웃는사나이 2022. 11. 15.

NodePort란?

  • 모든 node를 대상으로 외부 접속 가능한 port를 예약
  • Default NodePort 범위 : 30000 - 32767
  • ClusterIP를 생성 후 NodePort를 예약
  • definition
apiVersion: v1
kind: Service
metadata:
  name: nodeport-service
spec:
  type: NodePort
  clusterIP: 10.100.100.200       # 생략 시 random 생성
  selector:
    app: webui
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
    nodePort: 30200               # 생략 시 random 생성

 

[ Hands - on ]

  • Deployment를 통해서 pod 생성
 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: webui
spec:
  replicas: 3
  selector:
    matchLabels:
      app: webui
  template:
    metadata:
      name: nginx-pod
      labels:
        app: webui
    spec:
      containers:
      - name: nginx-container
        image: nginx:1.14
kubectl create -f deploy-nginx.yaml

 

  • nodeport 생성
vi nodeport-nginx.yaml

apiVersion: v1
kind: Service
metadata:
  name: nodeport-service
spec:
  type: NodePort
  clusterIP: 10.100.100.200
  selector:
    app: webui
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
    nodePort: 30200
kubectl create -f nodeport-nginx.yaml

 

  • nodeport 생성 확인
kubectl get service nodeport-service

NAME               TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
nodeport-service   NodePort   10.100.100.200   <none>        80:30200/TCP   32s
 
kubectl describe service nodeport-service

Name:                     nodeport-service
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=webui
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.100.100.200
IPs:                      10.100.100.200
Port:                     <unset>  80/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  30200/TCP
Endpoints:                192.168.11.65:80,192.168.11.66:80,192.168.221.2:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

 

 

 

참고 : [따배쿠] 7-2. 쿠버네티스 Service 4가지 종류 실습해보기

'INFRA > DevOps' 카테고리의 다른 글

[k8s] ExternalName  (0) 2022.11.28
[K8s] LoadBalancer (AKS에서 진행)  (0) 2022.11.21
[K8s] Cluster IP  (0) 2022.11.09
[k8s] Cronjob  (0) 2022.11.01
[K8s] Job Controller  (0) 2022.10.24

댓글