Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info
iconfalse
title목차

Table of Contents

개요

  • Kubernetes 배포 파일을 작성하고, 어플리케이션을 배포해 볼 것입니다.

사전조건

배포할 환경 미리보기

Info


Kubernetes 배포 파일 작성

  • Code Block
    themeMidnight
    titlek8s-deploy.yml
    linenumberstrue
    ---
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: redis
      spec:
        selector:
          matchLabels:
            app: redis
        replicas: 1
        template:
          metadata:
            labels:
              app: redis
          spec:
            containers:
            - name: redis
              image: redis
              ports:
              - containerPort: 6379
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: spring-demo
    spec:
      selector:
        matchLabels:
          app: spring-demo
      replicas: 3
      template:
        metadata:
          labels:
            app: spring-demo
        spec:
          containers:
          - name: spring-demo
            image: sooabia/spring-demo:1.0
            ports:
            - containerPort: 8080
    --- 
    kind: Service
    apiVersion: v1
    metadata:
      name: spring-service
    spec:
      selector:
        app: spring-demo
      ports:
      - protocol: TCP
        port: 80
        targetPort: 8080
      type: LoadBalancer
    --- 
    kind: Service
    apiVersion: v1
    metadata:
      name: redis
    spec:
      selector:
        app: redis
      ports:
      - protocol: TCP
        port: 6379
        targetPort: 6379
      type: ClusterIP

배포

  • Code Block
    languagebash
    themeMidnight
    linenumberstrue
    C:\Users\Sanse\Desktop\VSCODE_WORK>kubectl apply -f k8s-deploy.yml
    deployment.apps/redis created
    deployment.apps/webflux-demo created
    service/spring-service created
    service/redis created
    
    C:\Users\Sanse\Desktop\VSCODE_WORK>kubectl get pod
    NAME                            READY   STATUS    RESTARTS   AGE
    redis-5cdcc799b8-vjlj4          1/1     Running   0          111s
    webflux-demo-7fc4f88fb4-5xmzh   1/1     Running   0          111s
    webflux-demo-7fc4f88fb4-6qhgp   1/1     Running   0          111s
    webflux-demo-7fc4f88fb4-ph75s   1/1     Running   0          111s
    
    C:\Users\Sanse\Desktop\VSCODE_WORK>kubectl get svc
    NAME             TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
    kubernetes       ClusterIP      10.96.0.1       <none>        443/TCP        3h4m
    redis            ClusterIP      10.111.176.75   <none>        6379/TCP       115s
    spring-service   LoadBalancer   10.96.172.92    localhost     80:31913/TCP   115s

서비스 확인

  • Code Block
    linenumberstrue
    C:\Users\Sanse\Desktop\VSCODE_WORK>curl -XPOST http://localhost/link -H "Content-Type: application/json" -d "{\"link\":\"http://wiki.iisanse.com\"}"
    {"shortenedLink":"TPUqoo"}