본문 바로가기

리눅스

[kubernetes] 웹 서버(nginx) 배포(deployment)

반응형

kubernetes 웹 서버(nginx) 배포

 

도커 이미지 확인

$ docker search nginx
NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
nginx                              Official build of Nginx.                        13956               [OK]

 

쿠버네티스 네임스페이스 생성

###네임스페이스 생성
$ kubectl create namespace nginx-namespace
namespace/nginx-namespace created

###네임스페이지 확인
$ kubectl get namespace | grep nginx-namespace
nginx-namespace        Active   62s

 

쿠버네티스 웹 서버(nginx) 배포

###디플로이먼트 생성
$ kubectl create deployment nginx --image=nginx -n nginx-namespace
deployment.apps/nginx created

###파드 및 디플로이먼트 확인
$ kubectl get pod,service,deployment -o wide -n nginx-namespace
NAME                         READY   STATUS    RESTARTS   AGE   IP           NODE     NOMINATED NODE   READINESS GATES
pod/nginx-6799fc88d8-hfqkl   1/1     Running   0          39s   10.244.2.9   bk8sn2   <none>           <none>

NAME                    READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES   SELECTOR
deployment.apps/nginx   1/1     1            1           39s   nginx        nginx    app=nginx

 

쿠버네티스 서비스 생성

###서비스 생성
$ kubectl create service nodeport nginx --tcp=80:80 -n nginx-namespace
service/nginx created

###서비스 확인
$ kubectl get pod,service,deployment -o wide -n nginx-namespace
NAME                         READY   STATUS    RESTARTS   AGE     IP           NODE     NOMINATED NODE   READINESS GATES
pod/nginx-6799fc88d8-hfqkl   1/1     Running   0          2m13s   10.244.2.9   bk8sn2   <none>           <none>

NAME            TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE   SELECTOR
service/nginx   NodePort   10.99.250.28   <none>        80:30996/TCP   24s   app=nginx

NAME                    READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS   IMAGES   SELECTOR
deployment.apps/nginx   1/1     1            1           2m13s   nginx        nginx    app=nginx

 

웹(nginx) 서비스 확인

###NodePort 접속
$ curl -I 10.255.255.99:30996
HTTP/1.1 200 OK
Server: nginx/1.19.3
Date: Thu, 05 Nov 2020 04:56:41 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 29 Sep 2020 14:12:31 GMT
Connection: keep-alive
ETag: "5f7340cf-264"
Accept-Ranges: bytes

###CLUSTER-IP 접속
$ curl -I 10.99.250.28
HTTP/1.1 200 OK
Server: nginx/1.19.3
Date: Thu, 05 Nov 2020 04:57:18 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 29 Sep 2020 14:12:31 GMT
Connection: keep-alive
ETag: "5f7340cf-264"
Accept-Ranges: bytes

 

편집

$ kubectl edit deployments nginx -n nginx-namespace

# 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: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  creationTimestamp: "2020-11-05T04:53:05Z"
  generation: 1
  labels:
    app: nginx
  name: nginx
  namespace: nginx-namespace
  resourceVersion: "552799"
  selfLink: /apis/apps/v1/namespaces/nginx-namespace/deployments/nginx
  uid: ec964687-4f69-46ea-b921-b79cbeed370d
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: nginx
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: nginx
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
status:
  availableReplicas: 1
  conditions:
  - lastTransitionTime: "2020-11-05T04:53:10Z"
    lastUpdateTime: "2020-11-05T04:53:10Z"
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: "True"
    type: Available
  - lastTransitionTime: "2020-11-05T04:53:05Z"
    lastUpdateTime: "2020-11-05T04:53:10Z"
    message: ReplicaSet "nginx-6799fc88d8" has successfully progressed.
    reason: NewReplicaSetAvailable
    status: "True"
    type: Progressing
  observedGeneration: 1
  readyReplicas: 1
  replicas: 1
  updatedReplicas: 1

 

서비스 삭제

$ kubectl delete service dnginx -n nginx-namespace
service "dnginx" deleted

$ kubectl get service -o wide -n nginx-namespace
No resources found in nginx-namespace namespace.

 

디폴로이먼트 삭제

###deployment 삭제
$ kubectl delete deployment nginx -n nginx-namespace
deployment.apps "nginx" deleted

###deployment 확인
$ kubectl get deployment -o wide -n nginx-namespace
No resources found in nginx-namespace namespace.

###pod 확인
$ kubectl get pod -o wide -n nginx-namespace
No resources found in nginx-namespace namespace.

###pod,service,deployment 확인
$ kubectl get pod,service,deployment -o wide -n nginx-namespace
No resources found in nginx-namespace namespace.

 

네임스페이스 삭제

$ kubectl delete namespace <네임스페이스명>

$ kubectl delete namespace nginx-namespace
namespace "nginx-namespace" deleted

 

728x90
반응형