Kubernetes

Deployment를 이용해 Container 실행하기

chaenii 2022. 2. 5. 22:16

쿠버네티스를 이용해 컨테이너를 실행하는 방법에는 두 가지가 있다.

1. kubectl run 명령어 사용하기

2. yaml 형식으로 template으로 컨테이너 실행하기

 

kubectl run 명령어 사용하기

--image: 컨테이너 이미지 

--port: 컨테이너가 사용할 포트 지정

kubectl run <deployment_name> --image <image_name> --port=<port>
kubectl run nginx-app --image=nginx:1.14 --port=80

사용자가 kubernetes cluster에 container를 실행하라고 명령하면 지정된 container의 image가 docker hub와 같은 registry에서 가져와 cluster 안에서 실행하는 것이다.

 

yaml 형식으로 template으로 컨테이너 실행하기

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deploy
  labels:
    app: webui
spec:
  replicas: 3
  selector:
    matchLabels:
      app: webui
  template:
    metadata:
      name: nginx-pod
      labels:
        app: webui
    spec:
      containers:
      - name: nginx-container
        image: nginx:1.14

kubectl apply 명령어를 이용해 배포한다.

kubectl apply -f <yaml_file>
반응형