1 2 3 4 5 6 7 8 9 10 11 12 13 | apiVersion: v1 kind: Service metadata: labels: app: my-clusterip-svc name: my-clusterip-svc spec: ports: - port: 80 protocol: TCP targetPort: 80 selector: app: clusterip-test | cs |
12~13번: ClusterIP 서비스를 연결할 레플리카셋 또는 디플로이먼트의 레이블 값
kubectl create svc clusterip clusterip-test --tcp=80:80
or
kubectl expose deployment [디플로이먼트_이름] --port=[port] --target-port=[target-port]
kubectl get svc
kubectl get svc -n [네임스페이스]
kubectl get svc -A
kubectl get svc -o wide
kubectl describe svc [서비스_이름]
kubectl delete svc [서비스_이름]
1 2 3 4 5 6 7 8 9 10 11 | apiVersion: v1 kind: Service metadata: name: my-service spec: selector: name: nodeport-test ports: - protocol: TCP port: 80 targetPort: 80 | cs |
6~7번: NodePort 서비스를 연결할 레플리카셋 또는 디플로이먼트의 레이블 값
8~11번: NodePort를 별도로 설정하지 않을 경우 30000 ~ 32767 범위에서 자동 할당
kubectl create service nodeport [서비스_이름] --tcp=[port]:[targetPort]
or
kubectl expose deployment [디플로이먼트_이름] --port=[port] --target-port=[target-port] --type=NodePort
yaml를 활용한 LoadBalancer 서비스 생성
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | apiVersion: v1 kind: Service metadata: labels: app: frontend name: my-loadbalncer-test spec: ports: - port: 80 protocol: TCP targetPort: 8080 selector: app: frontend type: LoadBalancer | cs |
명령어를 활용한 LoadBalancer 서비스 생성
kubectl create service loadbalancer [서비스_이름] --tcp=[port]:[targetPort]
or
kubectl expose deployment [디플로이먼트_이름] --port=[port] --target-port=[target-port] --type=LoadBalancer
1 2 3 4 5 6 7 | apiVersion: v1 kind: Service metadata: name: my-service spec: type: ExternalName externalName: zero.test.com | cs |
kubectl create service externalname [서비스_이름] --external-name [DNS]