티스토리 뷰
ClusterIP
실습 디렉토리 이동
cd ~/k8s/lab6-clusterip
1. Service 조회
kubectl get service
kubectl get svc
kubernetes ClusterIP <none> 443/TCP 23h
root@k8s-master:~/k8s/lab6-clusterip# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP <none> 443/TCP 23h
2. yaml 확인
cat pod.yaml
cat svc-clusterip.yaml
apiVersion: v1
kind: Pod
metadata:
name: lab6-pod1
labels:
app: svc
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
apiVersion: v1
kind: Service
metadata:
name: lab6-svc
spec:
selector:
app: svc
ports:
- port: 9090
targetPort: 80
type: ClusterIP
3. yaml 을 활용한 ClusterIP 유형의 Service및 pod 생성
kubectl create -f svc-clusterip.yaml
kubectl create -f pod.yaml
4. 위 3에서 만든 리소스 확인
kubectl get pod
kubectl get svc
lab6-pod1 1/1 Running 0 5s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP <none> 443/TCP 23h
lab6-svc ClusterIP <none> 9090/TCP 32s
5. curl 명령을 통한 통신 확인
curl <lab6-svc의 ClusterIP>:9090
4에서 확인한 IP를 입력합니다.
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
6. 리소스 삭제
kubectl delete pod,svc --all
pod "lab6-pod1" deleted
service "kubernetes" deleted
service "lab6-svc" deleted
NodePort Service
실습 디렉토리 이동
cd ~/k8s/lab7-nodeport
1. yaml 확인
cat pod.yaml
cat svc-nodeport.yaml
apiVersion: v1
kind: Pod
metadata:
name: lab6-pod2
labels:
app: svc
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
apiVersion: v1
kind: Service
metadata:
name: lab7-svc
spec:
selector:
app: svc
ports:
- port: 9090
targetPort: 80
nodePort: 30000
type: NodePort
2. yaml 을 활용한 NodePort 유형의 Service및 pod 생성
kubectl create -f svc-nodeport.yaml
kubectl create -f pod.yaml
3. 생성된 Service 확인
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP <none> 443/TCP 2m21s
lab7-svc NodePort <none> 9090:30000/TCP 9s
4. Worker1 로의 접근을 통해 통신 확인
curl <Worker 1 노드의 IP>:30000
5. Worker2 로의 접근을 통해 통신 확인
curl <Worker 2 노드의 IP>:30000
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
6. 리소스 삭제
kubectl delete pod,svc --all
Loadbalancer Service
실습 디렉토리 이동
cd ~/k8s/lab8-loadbalancer
1. yaml 확인
cat pod.yaml
cat svc-loadbalancer.yaml
2. yaml 을 활용한 Loadbalancer 유형의 Service및 pod 생성
kubectl create -f svc-loadbalancer.yaml
kubectl create -f pod.yaml
3. 생성한 Service 확인
kubectl get svc
ExternalIP 를 발급받지 못하는 Pending 상태 확인
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP <none> 443/TCP 4m58s
lab8-svc LoadBalancer <pending> 9090:32263/TCP 9s
4. Loadbalancer 타입의 서비스가 생성한 ClusterIP 를 활용하여 내부에서 접근 시도
curl <Loadbalancer 타입의 서비스의 ClusterIP>:9090
html 출력 확인
5. Loadbalancer 타입의 서비스가 생성한 NodePort 를 활용하여 외부에서 접근 시도
curl <아무 Worker IP>:<Loadbalancer 타입의 서비스의 NodePort>
예시 : workerIP:3만대 포트