[kubenetes] 6-1. 서비스 - ClusterIP
kubenetes
Author
Date
2022-07-25 21:25
Views
1211
ClusterIP 생성
root@Kube-master1:~# cat hostname-svc-clusterip.yaml apiVersion: v1 kind: Service metadata: name: hostname-svc-clusterip spec: ports: - name : web-port port: 8080 targetPort: 80 selector: app: webserver type: ClusterIP root@Kube-master1:~# kubectl apply -f hostname-svc-clusterip.yaml
ClusterIP 생성 확인
root@Kube-master1:~# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hostname-svc-clusterip ClusterIP 10.107.167.210 8080/TCP 18h kubernetes ClusterIP 10.96.0.1 443/TCP 43h
서비스 IP와 포트를 통해 포드에 접근가능, 별도의 설정없이 로드밸런싱 수행
root@Kube-master1:~# kubectl run -it --tty --rm debug --image=alicek106/ubuntu:curl --restart=Never -- bash If you don't see a command prompt, try pressing enter. root@debug:/# curl 10.107.167.210:8080 --silent | grep Hello
Hello, hostname-deployment-7dfd748479-jqzmp
root@debug:/# curl 10.107.167.210:8080 --silent | grep Hello
Hello, hostname-deployment-7dfd748479-v8lb2
root@debug:/# curl 10.107.167.210:8080 --silent | grep Hello
Hello, hostname-deployment-7dfd748479-fvg7n
내부 DNS 를 사용하고있어 서비스 이름 자체로도 접근 가능
root@debug:/# curl hostname-svc-clusterip:8080 --silent | grep Hello
Hello, hostname-deployment-7dfd748479-fvg7n
서비스의 라벨 셀렉터와 포드의 라벨이 매칭돼 연결되면 쿠버네티스는 자동으로 엔드포인트라고 부르는 오브젝트를 생성한다.
엔드포인트 오브젝트는 서비스가 가리키고있는 도착점을 나타낸다.
root@Kube-master1:~# kubectl get endpoints root@Kube-master1:~# kubectl get ep NAME ENDPOINTS AGE hostname-svc-clusterip 192.168.130.140:80,192.168.161.202:80,192.168.194.11:80 18h kubernetes 192.168.122.140:6443 43h
서비스 삭제
root@Kube-master1:~# kubectl delete svc hostname-svc-clusterip service "hostname-svc-clusterip" deleted
kubectl run -i -tty --rm debug --image=alicek106/window:curl --restart=Never -- bash
이부분 에 오류가 난다면 우분투 환경이 아니라 발생하는걸까요?
kubectl get pods
하시면
debug 가 있을텐데
kubectl delete pods debug 로 지우시고
해보세요
감사합니다~