추가 확인 필요 - 이론만 확인하세요
nodeport 서비스는 외부에서 접근 할수 있는 서비스이다.
서비스 노드 포트를 이용해 Pod에 접속 해보가.
//아래 내용은 마스터 node 접속 불가로 추가 확인 필요~
1
동작 ?
node port 접속시 nat되어 pod 에서 소스 ip를 알수 없음
구조
nodeport -> cluster ip -> pod ip
2
pod 3개 생성됨
topasvga@cloudshell:~ (ap-seoul-1)$ cat << EOF > nginx11.yaml
> apiVersion: apps/v1
> kind: Deployment
> metadata:
> name: deploy-nginx11
> spec:
> replicas: 3
> selector:
> matchLabels:
> app: deploy-nginx11
> template:
> metadata:
> labels:
> app: deploy-nginx11
> spec:
> containers:
> - name: deploy-nginx11
> image: nginx:1.11
> EOF
3
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl apply -f nginx11.yaml
deployment.apps/deploy-nginx11 created
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get pods
NAME READY STATUS RESTARTS AGE
deploy-nginx11-6489d4db8b-dfwnl 1/1 Running 0 8s
deploy-nginx11-6489d4db8b-k4qx2 1/1 Running 0 8s
deploy-nginx11-6489d4db8b-rkxpj 1/1 Running 0 8s
4
index.html 내용 변경
topasvga@cloudshell:~ (ap-seoul-1)$ for pod in $(kubectl get pod -l app=deploy-nginx11 |awk 'NR>1 {print $1}'); do kubectl exec $pod -- /bin/sh -c "hostname > /usr/share/nginx/html/index.html; echo 'nginx:v1.11 END' >> /usr/share/nginx/html/index.html"; done
5
로그 확인
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl logs -l app=deploy-nginx11 -f
topasvga@cloudshell:~ (ap-seoul-1)$ cat << EOF > svc-nodeport.yaml
> apiVersion: v1
> kind: Service
> metadata:
> name: svc-nodeport
> spec:
> ports:
> - name: svc-webport
> port: 9000
> targetPort: 80
> selector:
> app: deploy-nginx11
> type: NodePort
> EOF
// 타입은 nodeport 임
// 클러스터 ip로 접근할때는 9000
// 실제 pod에 접근할때 80
// nodePort는 30000~32767번으로 램던하게 됨
// 노드포트는 클러스터 IP를 포함한다.
6
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl apply -f svc-nodeport.yaml
service/svc-nodeport created
7
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get service svc-nodeport
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc-nodeport NodePort 10.96.94.203 <none> 9000:31312/TCP 13s
// 30865 노드 포트
8
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get nodes -A -owide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
10.0.10.141 Ready node 6d22h v1.25.4 10.0.10.141 <none> Oracle Linux Server 8.6 5.4.17-2136.314.6.2.el8uek.x86_64 cri-o://1.25.1-111.el8
10.0.10.80 Ready node 6d22h v1.25.4 10.0.10.80 <none> Oracle Linux Server 8.6 5.4.17-2136.314.6.2.el8uek.x86_64 cri-o://1.25.1-111.el8
9
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get service svc-nodeport
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc-nodeport NodePort 10.96.94.203 <none> 9000:31312/TCP 112s
10
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl delete deploy,svc --all
deployment.apps "deploy-nginx11" deleted
service "kubernetes" deleted
service "svc-nodeport" deleted
11
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl delete deploy,svc,pod --all
service "kubernetes" deleted
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get pods,svc,ep -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 8s <none>
NAME ENDPOINTS AGE
endpoints/oracle.com-oci <none> 29m
참고 사이트
https://brunch.co.kr/@topasvga/1684
감사합니다.