본문 바로가기

리눅스

[Kubernetes] kubernetes nginx 배포 테스트 -2

반응형

kubernetes nginx 배포 테스트 -2

 

nginx 컨테이너 실행

root@bk8sm1:~$ kubectl run nginx-app --image nginx --port=80
pod/nginx-app created


###kubectl get pods -o wide
root@bk8sm1:~$ kubectl get pods --output=wide
NAME        READY   STATUS    RESTARTS   AGE   IP           NODE     NOMINATED NODE   READINESS GATES
nginx-app   1/1     Running   0          14m   10.244.2.2   bk8sn3   <none>           <none>

 

Serveivce 실행

root@bk8sm1:~$ kubectl expose pod nginx-app
service/nginx-app exposed


root@bk8sm1:~$ kubectl get service --output=wide
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE     SELECTOR
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP   34m     <none>
nginx-app    ClusterIP   10.96.146.160   <none>        80/TCP    5m21s   run=nginx-app


root@bk8sm1:~$ kubectl describe services nginx-app
Name:              nginx-app
Namespace:         default
Labels:            run=nginx-app
Annotations:       <none>
Selector:          run=nginx-app
Type:              ClusterIP
IP:                10.96.146.160
Port:              <unset>  80/TCP
TargetPort:        80/TCP
Endpoints:         10.244.2.2:80
Session Affinity:  None
Events:            <none>

 

클러스터 IP(ClusterIP)로 서비스 확인

root@bk8sm1:~$ curl 10.244.2.2:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    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>

 

외부 트래픽 허용(NodePort 설정)

kubectl edit service nginx-app(nginx-app 편집)

 type 편집 : CulsterIP -> NodePort

root@bk8sm1:~$ kubectl edit service nginx-app
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2020-10-05T03:12:15Z"
  labels:
    run: nginx-app
  name: nginx-app
  namespace: default
  resourceVersion: "4867"
  selfLink: /api/v1/namespaces/default/services/nginx-app
  uid: 2ae14e7a-5c3a-45bb-8461-f50f3ab52f27
spec:
  clusterIP: 10.96.146.160
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    run: nginx-app
  sessionAffinity: None
  #type: ClusterIP
  type: NodePort
status:
  loadBalancer: {}
  
  :wq!
  Edit cancelled, no changes made.

 

(or) kubectl로 설정

$ kubectl expose deployment nginx-app --type=NodePort

 

NodePort 확인

root@bk8sm1:~$ kubectl get service -o wide
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE   SELECTOR
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP        21h   <none>
nginx-app    NodePort    10.96.146.160   <none>        80:30546/TCP   20h   run=nginx-app

 

외부 포트(NodePort)로 웹 서비스 확인

 

 

nginx 컨테이너(container) 제거

$ kubectl delete deployment nginx-app

$ kubectl get deployments


$ kubectl delete service nginx-app

$ kubectl get service -o wide     
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE   SELECTOR
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   21h   <none>


$ kubectl delete pods nginx-app
pod "nginx-app" deleted

$ kubectl get pods --output=wide
No resources found in default namespace.

 

 

 

728x90
반응형