<미션> 서비스 리소스 생성 1. 디폴트로 생성 --> curl명령 또는 k8snode1에서 확인 2. nodeport 방식으로 서비스 생성 --> curl 명령을 통해 cluster IP 접속 / 로컬호스트 IP로 접속 (100/101:30123) 3. LoadBalancer 타입 생성 --> external IP 로 로컬 호스트에서 접속 테스트, nodeport 방식으로 접속 테스트, cluster IP로 접속 테스트 |
< ReplicaSet을 이용하여 guestbook POD 생성 >
[root@k8smaster ~]# cd ~/lab/05
[root@k8smaster 05]# kubectl create -f guestbook-replicaset.yaml
replicaset.apps/guestbook created
[root@k8smaster 05]# kubectl create -f guestbook-svc.yaml
service/guestbook created
[root@k8smaster 05]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
guestbook ClusterIP 10.104.89.251 <none> 80/TCP 10s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 13m
[root@k8smaster 05]# kubectl get po -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
guestbook-b92ph 1/1 Running 0 43s 10.102.249.11 k8snode1 <none> <none>
guestbook-k49gr 1/1 Running 0 43s 10.102.249.25 k8snode1 <none> <none>
guestbook-tm6x8 1/1 Running 0 43s 10.98.16.161 k8smaster <none> <none>
[root@k8smaster 05]# kubectl describe svc guestbook
Name: guestbook
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=guestbook
Type: ClusterIP
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.104.89.251
IPs: 10.104.89.251
Port: <unset> 80/TCP
TargetPort: 8080/TCP
Endpoints: 10.102.249.11:8080,10.102.249.25:8080,10.98.16.161:8080
Session Affinity: None
Events: <none>
[root@k8smaster 05]# ls
guestbook-rc-readinessprobe.yaml guestbook-svc-named-ports.yaml metalLB
guestbook-replicaset.yaml guestbook-svc-nodeport.yaml named-port
guestbook-svc-client-ip-session-affinity.yaml guestbook-svc.yaml
guestbook-svc-loadbalancer.yaml ingress
[root@k8smaster 05]# curl http://10.104.89.251
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="/common.css" rel="stylesheet">
<link href="/guestbook.css" rel="stylesheet">
<title>방명록 (K8S)</title>
</head>
<body>
<div class="guestbook list displaynone" style="display: block;">
<ul class="cont">
<li>
<p class="memo">
HealthCheck : This is v1 running in pod guestbook-k49gr (10.102.249.25)
</p>
</li>
</ul>
</div>
<h4 class="g-top">방명록 v1(정환열)</h4>
<div class="top-img">
<img src="/bg-guestbook.jpg">
</div>
<form action="/" method="post" id="frm" enctype="multipart/form-data">
<div class="g-cont">
<ul>
<li class="name"><input name="name" type="text" maxlength="20" placeholder="이름" class="form-control"></li>
<li class="msg"><textarea name="content" maxlength="200" placeholder="내용을 입력해주세요" class="form-control" rows="3"></textarea></li>
<li>파일첨부<input type="file" name="uploadingFile"></li>
</ul>
<p class="btn btn-lg" onclick="document.getElementById('frm').submit();">방명록 남기기</p>
</div>
</form>
<div class="guestbook list displaynone" style="display: block;">
<ul class="cont">
<li>
<p class="name">최유진</p>
<p class="date">2024-09-25 03:43:41</p>
<p class="memo">방명록</p>
첨부파일 : <a href="/downloadFile/null"></a>
</li>
</ul>
</div>
</body>
2. nodeport 방식으로 서비스 생성 --> curl 명령을 통해 cluster IP 접속 / 로컬호스트 IP로 접속 (100/101:30123)
</html>[root@k8smaster 05]# ls
guestbook-rc-readinessprobe.yaml guestbook-svc-named-ports.yaml metalLB
guestbook-replicaset.yaml guestbook-svc-nodeport.yaml named-port
guestbook-svc-client-ip-session-affinity.yaml guestbook-svc.yaml
guestbook-svc-loadbalancer.yaml ingress
[root@k8smaster 05]# k create -f guestbook-svc-nodeport.yaml
service/guestbook-nodeport created
[root@k8smaster 05]# k get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
guestbook ClusterIP 10.104.89.251 <none> 80/TCP 19m
guestbook-nodeport NodePort 10.96.91.156 <none> 80:30123/TCP 27s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 32m
[root@k8smaster 05]# k describe svc guestbook-nodeport
Name: guestbook-nodeport
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=guestbook
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.96.91.156
IPs: 10.96.91.156
Port: <unset> 80/TCP
TargetPort: 8080/TCP
NodePort: <unset> 30123/TCP
Endpoints: 10.102.249.11:8080,10.102.249.25:8080,10.98.16.161:8080
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
[root@k8smaster 05]# curl 10.96.91.156
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="/common.css" rel="stylesheet">
<link href="/guestbook.css" rel="stylesheet">
<title>방명록 (K8S)</title>
</head>
<body>
<div class="guestbook list displaynone" style="display: block;">
<ul class="cont">
<li>
<p class="memo">
HealthCheck : This is v1 running in pod guestbook-tm6x8 (10.98.16.161)
</p>
</li>
</ul>
</div>
<h4 class="g-top">방명록 v1(정환열)</h4>
<div class="top-img">
<img src="/bg-guestbook.jpg">
</div>
<form action="/" method="post" id="frm" enctype="multipart/form-data">
<div class="g-cont">
<ul>
<li class="name"><input name="name" type="text" maxlength="20" placeholder="이름" class="form-control"></li>
<li class="msg"><textarea name="content" maxlength="200" placeholder="내용을 입력해주세요" class="form-control" rows="3"></textarea></li>
<li>파일첨부<input type="file" name="uploadingFile"></li>
</ul>
<p class="btn btn-lg" onclick="document.getElementById('frm').submit();">방명록 남기기</p>
</div>
</form>
<div class="guestbook list displaynone" style="display: block;">
<ul class="cont">
<li>
<p class="name">최유진</p>
<p class="date">2024-09-25 03:43:41</p>
<p class="memo">방명록</p>
첨부파일 : <a href="/downloadFile/null"></a>
</li>
</ul>
</div>
</body>
로컬호스트에 접속 ->
3. LoadBalancer 타입 생성 --> external IP 로 로컬 호스트에서 접속 테스트, nodeport 방식으로 접속 테스트, cluster IP로 접속 테스트
</html>[root@k8smaster 05]# cd metalLB
[root@k8smaster metalLB]# kubectl create -f metallb-native.yaml
namespace/metallb-system created
customresourcedefinition.apiextensions.k8s.io/addresspools.metallb.io created
customresourcedefinition.apiextensions.k8s.io/bfdprofiles.metallb.io created
customresourcedefinition.apiextensions.k8s.io/bgpadvertisements.metallb.io created
customresourcedefinition.apiextensions.k8s.io/bgppeers.metallb.io created
customresourcedefinition.apiextensions.k8s.io/communities.metallb.io created
customresourcedefinition.apiextensions.k8s.io/ipaddresspools.metallb.io created
customresourcedefinition.apiextensions.k8s.io/l2advertisements.metallb.io created
serviceaccount/controller created
serviceaccount/speaker created
role.rbac.authorization.k8s.io/controller created
role.rbac.authorization.k8s.io/pod-lister created
clusterrole.rbac.authorization.k8s.io/metallb-system:controller created
clusterrole.rbac.authorization.k8s.io/metallb-system:speaker created
rolebinding.rbac.authorization.k8s.io/controller created
rolebinding.rbac.authorization.k8s.io/pod-lister created
clusterrolebinding.rbac.authorization.k8s.io/metallb-system:controller created
clusterrolebinding.rbac.authorization.k8s.io/metallb-system:speaker created
secret/webhook-server-cert created
service/webhook-service created
deployment.apps/controller created
daemonset.apps/speaker created
validatingwebhookconfiguration.admissionregistration.k8s.io/metallb-webhook-configuration created
[root@k8smaster metalLB]# ls
metallb-ippool.yaml metallb-l2advertisement.yaml metallb-native.yaml
[root@k8smaster metalLB]# k get ns
NAME STATUS AGE
default Active 280d
kube-node-lease Active 280d
kube-public Active 280d
kube-system Active 280d
kubernetes-dashboard Active 5d20h
metallb-system Active 2m43s
shopping-mall Active 3d22h
# 외부공개용IP Address Pool 생성
[root@k8smaster metalLB]# k create -f metallb-ippool.yaml
ipaddresspool.metallb.io/ip-pool created
# Layer 2에서 사용한 NIC 인터페이스설정
[root@k8smaster metalLB]# kubectl create -f metallb-l2advertisement.yaml
# “metallb-system” 네임스페이스에 생성된 쿠버네티스 리소스 조회
[root@k8smaster metalLB]# k -n metallb-system get all
NAME READY STATUS RESTARTS AGE
pod/controller-67d9f4b5bc-7pgdk 1/1 Running 0 115s
pod/speaker-6rn9g 1/1 Running 0 115s
pod/speaker-tzdrl 1/1 Running 0 115s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/webhook-service ClusterIP 10.98.171.102 <none> 443/TCP 115s
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
daemonset.apps/speaker 2 2 2 2 2 kubernetes.io/os=linux 115s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/controller 1/1 1 1 115s
NAME DESIRED CURRENT READY AGE
replicaset.apps/controller-67d9f4b5bc 1 1 1 115s
[root@k8smaster metalLB]# cd ~/lab/05
[root@k8smaster 05]# k create -f guestbook-svc-loadbalancer.yaml
service/guestbook-loadbalancer created
[root@k8smaster 05]# k get svc guestbook-loadbalancer
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
guestbook-loadbalancer LoadBalancer 10.103.117.174 192.168.56.201 80:32450/TCP 7s
[root@k8smaster 05]# k describe svc guestbook-loadbalancer
Name: guestbook-loadbalancer
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=guestbook
Type: LoadBalancer
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.103.117.174
IPs: 10.103.117.174
LoadBalancer Ingress: 192.168.56.201
Port: <unset> 80/TCP
TargetPort: 8080/TCP
NodePort: <unset> 32450/TCP
Endpoints: 10.102.249.11:8080,10.102.249.25:8080,10.98.16.161:8080
Session Affinity: None
External Traffic Policy: Cluster
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal IPAllocated 13s metallb-controller Assigned IP ["192.168.56.201"]
Normal nodeAssigned 13s metallb-speaker announcing from node "k8snode1" with protocol "layer2"
[root@k8smaster 05]# k get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
guestbook ClusterIP 10.104.89.251 <none> 80/TCP 34m
guestbook-loadbalancer LoadBalancer 10.103.117.174 192.168.56.201 80:32450/TCP 24s
guestbook-nodeport NodePort 10.96.91.156 <none> 80:30123/TCP 15m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 48m
[root@k8smaster 05]# curl http://10.103.117.174
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="/common.css" rel="stylesheet">
<link href="/guestbook.css" rel="stylesheet">
<title>방명록 (K8S)</title>
</head>
<body>
<div class="guestbook list displaynone" style="display: block;">
<ul class="cont">
<li>
<p class="memo">
HealthCheck : This is v1 running in pod guestbook-tm6x8 (10.98.16.161)
</p>
</li>
</ul>
</div>
<h4 class="g-top">방명록 v1(정환열)</h4>
<div class="top-img">
<img src="/bg-guestbook.jpg">
</div>
<form action="/" method="post" id="frm" enctype="multipart/form-data">
<div class="g-cont">
<ul>
<li class="name"><input name="name" type="text" maxlength="20" placeholder="이름" class="form-control"></li>
<li class="msg"><textarea name="content" maxlength="200" placeholder="내용을 입력해주세요" class="form-control" rows="3"></textarea></li>
<li>파일첨부<input type="file" name="uploadingFile"></li>
</ul>
<p class="btn btn-lg" onclick="document.getElementById('frm').submit();">방명록 남기기</p>
</div>
</form>
<div class="guestbook list displaynone" style="display: block;">
<ul class="cont">
<li>
<p class="name">최유진</p>
<p class="date">2024-09-25 03:43:41</p>
<p class="memo">방명록</p>
첨부파일 : <a href="/downloadFile/null"></a>
</li>
</ul>
</div>
</body>
</html>[root@k8smaster 05]# curl http://192.168.56.201
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="/common.css" rel="stylesheet">
<link href="/guestbook.css" rel="stylesheet">
<title>방명록 (K8S)</title>
</head>
<body>
<div class="guestbook list displaynone" style="display: block;">
<ul class="cont">
<li>
<p class="memo">
HealthCheck : This is v1 running in pod guestbook-b92ph (10.102.249.11)
</p>
</li>
</ul>
</div>
<h4 class="g-top">방명록 v1(정환열)</h4>
<div class="top-img">
<img src="/bg-guestbook.jpg">
</div>
<form action="/" method="post" id="frm" enctype="multipart/form-data">
<div class="g-cont">
<ul>
<li class="name"><input name="name" type="text" maxlength="20" placeholder="이름" class="form-control"></li>
<li class="msg"><textarea name="content" maxlength="200" placeholder="내용을 입력해주세요" class="form-control" rows="3"></textarea></li>
<li>파일첨부<input type="file" name="uploadingFile"></li>
</ul>
<p class="btn btn-lg" onclick="document.getElementById('frm').submit();">방명록 남기기</p>
</div>
</form>
<div class="guestbook list displaynone" style="display: block;">
<ul class="cont">
<li>
<p class="name">최유진</p>
<p class="date">2024-09-25 03:43:41</p>
<p class="memo">방명록</p>
첨부파일 : <a href="/downloadFile/null"></a>
</li>
</ul>
</div>
</body>
-> external IP 로 로컬 호스트에서 접속 테스트
-> nodeport 방식으로 접속 테스트
-> cluster IP로 접속
'Kubernetes' 카테고리의 다른 글
쿠버네티스 (RollingUpdate, 애플리케이션 설정) (0) | 2024.10.04 |
---|---|
쿠버네티스 (인그레스) (0) | 2024.10.02 |
쿠버네티스 (서비스 리소스 생성- nodeport 방식, LoadBalancer 타입 생성) (0) | 2024.10.01 |
쿠버네티스 (YAML 디스크립터를 통한 서비스생성) (0) | 2024.09.30 |
쿠버네티스 (ReplicationController 의 생성) (0) | 2024.09.30 |