CKA (Certified Kubernetes Administrator)/Kode Kloud

01.CoreConcepts - Imperative Commands

seulseul 2022. 1. 19. 10:56

All the questions in this lab can be done imperatively. However, for some questions, you may need to first create the YAML file using imperative methods. You can then modify the YAML according to the need and create the object using kubectl apply -f command.

 

02. Deploy a pod named nginx-pod using the nginx:alpine image.
Use imperative commands only.

  • Name: nginx-pod
  • Image: nginx:alpine
kubectl run nginx-pod --image nginx:alpine

03. 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.

  • Pod Name: redis
  • Image: redis:alpine
  • Labels: tier=db
kubectl run redis --image=redis:alpine -l tier=db
# label 확인
kubectl get pod -l tier=db

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

Use imperative commands.

  • Service: redis-service
  • Port: 6379
  • Type: ClusterIP
kubectl expose pod redis --port=6379 --name redis-service

5. 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 webapp --image=kodekloud/webapp-color --replicas=3 # 삭제시 kubectl delete deployment webapp

06. Create a new pod called custom-nginx using the nginx image and expose it on container port 8080.
- Pod created correctly?

kubectl run custom-nginx --image=nginx --port=8080


07. Create a new namespace called dev-ns.

Use imperative commands.

  • Namespace created?
kubectl create namespace dev-ns
# namespace 생성됐는지 확인
kubectl get namespace

08. Create a new deployment called redis-deploy in the dev-ns namespace with the redis image. It should have 2 replicas.

Use imperative commands.

  • 'redis-deploy' created in the 'dev-ns' namespace?
  • replicas: 2
kubectl create deployment redis-deploy --namespace=dev-ns --image=redes --replicas=2
# 전부 확인
kubectl get all
Hint Step 1: Create the deployment YAML file kubectl create deployment redis-deploy --image redis --namespace=dev-ns --dry-run=client -o yaml > deploy.yaml Step 2: Edit the YAML file and add update the replicas to 2 Step 3: Run kubectl apply -f deploy.yaml to create the deployment in the dev-ns namespace. You can also use kubectl scale deployment or kubectl edit deployment to change the number of replicas once the object has been created.

09. Create a pod called httpd using the image httpd:alpine in the default namespace.

Next, create a service of type ClusterIP by the same name (httpd).

The target port for the service should be 80.

Try to do this with as few steps as possible.

  • httpd' pod created with the correct image?
  • 'httpd' service is of type 'ClusterIP'?
  • 'httpd' service uses correct target port 80?
  • 'httpd' service exposes the 'httpd' pod?
controlplane ~ ➜  kubectl run httpd --image=httpd:alpine --port=80 --expose
service/httpd created
pod/httpd created

# 오답,,,
controlplane ~ ✖ kubectl create deployment httpd --image=httpd:alpine --port=80
deployment.apps/httpd created

 

# Tip
cka 시험을 볼때는 kubernetes 공식홈페이지에서만 검색할수 있다고함.
아래 URL은 kubectl 명령어 설명돼있음.
https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#expose