모든 노드를 대상으로 외부에서 접속이 가능한 포트를 예약하는 기능을 제공
- 기본 포트 :
30000 ~ 32767을 사용하고 있으며, ClusterIP(必)가 설정된 이후 예약됨- ClusterIP 주소를 이용하지 않고
노드 IP 주소:노드 포트 번호형식으로 접근 가능
[root@master ~/kube/08/nodeport]# vi nginx-nodeport.yaml
[root@master ~/kube/08/nodeport]# cat nginx-nodeport.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-nodeport
spec:
type: NodePort
clusterIP: 10.233.10.10
selector:
app: webui
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30200
[root@master ~/kube/08/nodeport]# kubectl apply -f nginx-nodeport.yaml
service/nginx-nodeport created
[root@master ~/kube/08/nodeport]# kubectl get pod,svc,ep -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/nginx-deploy-9cc457697-8bjql 1/1 Running 0 2m6s 10.233.102.172 node1 <none> <none>
pod/nginx-deploy-9cc457697-gq5fd 1/1 Running 0 2m6s 10.233.75.61 node2 <none> <none>
pod/nginx-deploy-9cc457697-lrks7 1/1 Running 0 2m6s 10.233.71.38 node3 <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/kubernetes ClusterIP 10.233.0.1 <none> 443/TCP 5h19m <none>
service/nginx-nodeport NodePort 10.233.10.10 <none> 80:30200/TCP 2m29s app=webui
NAME ENDPOINTS AGE
endpoints/kubernetes 192.168.2.60:6443 5h19m
endpoints/nginx-nodeport 10.233.102.172:80,10.233.71.38:80,10.233.75.61:80 2m29s
[root@master ~/kube/08/nodeport]# kubectl describe svc nginx-nodeport
Name: nginx-nodeport
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=webui
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.233.10.10
IPs: 10.233.10.10
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30200/TCP
Endpoints: 10.233.102.172:80,10.233.71.38:80,10.233.75.61:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
NodePort 테스트
[root@master ~/kube/08/nodeport]# curl <http://192.168.2.60:30200>
<h1>#2# TEST Page</h1>
[root@master ~/kube/08/nodeport]# curl <http://192.168.2.60:30200>
<h1>#1# TEST Page</h1>
[root@master ~/kube/08/nodeport]# curl <http://192.168.2.61:30200>
<h1>#2# TEST Page</h1>
[root@master ~/kube/08/nodeport]# curl <http://192.168.2.62:30200>
<h1>#2# TEST Page</h1>
[root@master ~/kube/08/nodeport]# curl <http://192.168.2.63:30200>
<h1>#2# TEST Page</h1>