Exercise 7.1: Exposing Applications: Expose a Service
Deployment 생성
kubectl create deploy nginx --image=nginxDeployment 및 Pod에 부여된 Label 확인
kubectl get deploy,pod -l app=nginx --show-labelsService 생성
cat <<EOF | kubectl apply -f - apiVersion: v1 kind: Service metadata: name: nginx spec: ports: - port: 80 protocol: TCP selector: app: nginx EOFCURL 명령어를 통해서 Service의 Cluster IP로 HTTP 요청
curl $(kubectl get service nginx -o=jsonpath='{.spec.clusterIP}')Deployment 생성
kubectl create deploy httpd --image=httpdService 업데이트
cat <<EOF | kubectl apply -f - apiVersion: v1 kind: Service metadata: name: nginx spec: ports: - port: 80 protocol: TCP selector: app: httpd EOFCURL 명령어를 통해서 Service의 Cluster IP로 HTTP 요청
curl $(kubectl get service nginx -o=jsonpath='{.spec.clusterIP}')Service 업데이트
cat <<EOF | kubectl apply -f - apiVersion: v1 kind: Service metadata: name: nginx spec: ports: - port: 80 protocol: TCP selector: app: nginx EOFCURL 명령어를 통해서 Service의 Cluster IP로 HTTP 요청
curl $(kubectl get service nginx -o=jsonpath='{.spec.clusterIP}')Deployment 삭제
kubectl delete deploy httpdService 업데이트
cat <<EOF | kubectl apply -f - apiVersion: v1 kind: Service metadata: name: nginx spec: type: NodePort ports: - port: 80 protocol: TCP nodePort: 32000 selector: app: nginx EOFCURL 명령어를 통해서 Service의 Cluster IP로 HTTP 요청
curl $(kubectl get service nginx -o=jsonpath='{.spec.clusterIP}')웹브라우저에서
ANY_NODE_IP:SERVICE_NODE_PORT로 접속되는지 확인 - 아래 명령어로 주소 확인 가능echo "$(curl -s ifconfig.io):$(kubectl get service nginx -o=jsonpath='{.spec.ports[0].nodePort}')"Service 업데이트
cat <<EOF | kubectl apply -f - apiVersion: v1 kind: Service metadata: name: nginx spec: type: LoadBalancer ports: - port: 80 protocol: TCP nodePort: 32000 selector: app: nginx EOFService 상태 확인
kubectl get svc nginxService에 발생한 Event 확인
kubectl describe svc nginxPod 생성
cat <<EOF | kubectl create -f - apiVersion: v1 kind: Pod metadata: name: alpine spec: containers: - name: alpine image: praqma/network-multitool command: [ "sleep" ] args: [ "infinity" ] EOF생성한 Pod로 Bash 연결
kubectl exec -it alpine -- /bin/bashCURL 명령어로 위에서 생성한 Service의 이름으로 접근 시도
curl nginx curl nginx.default curl nginx.default.svc위에서 생성한 Service 이름으로 IP 주소 확인
nslookup nginxDNS 서버 정보 확인
dig로컬 DNS 설정 정보 확인
cat /etc/resolv.confDNS 서버 상세 정보 확인
dig @10.96.0.10 -x 10.96.0.10Bash 프로세스 종료
exit데모 애플리케이션 배포
{ kubectl create ns demo kubectl create deploy httpd --image=httpd -n demo kubectl expose deploy httpd --port=80 -n demo }alpine Pod로 Bash 연결
kubectl exec -it alpine -- /bin/bashCURL 명령어로 위에서 생성한 Service의 이름으로 접근 시도
curl httpd curl httpd.demo curl httpd.demo.svcBash 프로세스 종료
exit리소스 삭제
{ kubectl delete svc nginx kubectl delete deploy nginx kubectl delete pod alpine kubectl delete ns demo }
Last updated