DevOps_k8s

[CKAD/Lab] Imperative commands

최선을 다하자! 2023. 9. 25. 09:19

Imperative command

 

 

예제1)

Deploy a redis pod using the redis:alpine image with the labels set to tier=db

Either use imperative commands to create the pod with the labels. 
Or else use imperative commands to generate the pod definition file, 
then add the labels before creating the pod using the file.

$ kubectl run redis --image=redis:alpine --labels tier=db

=> image 생성 및 label 생성 (kubectl run 명령어를 사용할 때 labels를 지정하는 올바른 방식은 --labels 옵션을 사용)

 

 

예제2)

Create a service redis-service to expose the redis application 
within the cluster on port 6379.

Use imperative commands.

$ kubectl create deployment --image=redis redis 

=> image가 redis인 deployment 생성 

 

$ kubectl expose deployment redis --name=redis-service --port=6379 --type=ClusterIP
service/redis-service exposed

=> deployment redis를 생성하고 옵션으로 name, port, type을 부여한다.

 

$ kubectl get deployments.apps redis 

=> redis인 deployment의 상태를 확인

NAME    READY   UP-TO-DATE   AVAILABLE   AGE
redis   1/1     1            1           4m51s

 

 

 

예제3)

Create a deployment named webapp 
using the image kodekloud/webapp-color with 3 replicas.

Try to use imperative commands only. Do not create definition files.


Name: webapp

Image: kodekloud/webapp-color

Replicas: 3

 

$ kubectl create deployment --image=kodekloud/webapp-color webapp --replicas=3