새소식

Recent Study/udemy - CKA with Practice Tests

KodeKloud - Test Record (section 2)

  • -

1. Pods

 

[ 1 ] Which nodes are these pods placed on?

 

> kubectl get pods -o wide

[ 해당 옵션으로 어떤 Node에 선정되었는지 볼 수 있었음 ]

 

 

[ 2 ] Create a new pod with the name redis and the image redis123. Use a pod - definition YAML file. And yes the image name is wrong!

> kubectl run redis —image=redis123 —dry-run=client -o yaml > redis.yaml
[ Print the result (in YAML format) of updated nginx deployment with the service account from local file, without hitting the API server ] 

> kubectl create -f redis.yaml

[ 현재 노드에 redis.yaml 사용하여 Pod가 생성되었음. 하지만 container가 아직 실행중이지 않음 ]

 

 

[ 3 ] Now change the image on this pod to redis. Once done, the pod should be in a running state. Use the kubectl edit command to update the image of the pod to redis. If you used a pod definition file then update the image from redis123 to redis in the definition file via Vi or Nano editor and then run kubectl apply command to update the image :-

> vi redis

[ 해당 pod 내용을 고친 후 :wq로 마무리해서 저장하면서 문제가 생겼던 것 같은데, :wq! 로 하면 적용되었음 ]

> kubectl apply -f redis-definition.yaml 

[ 실행 후 redis pod가 성공적으로 실행되었음 ]

 

 

2. Replicasets

[ 1 ] What is the image used to create the pods in the new-replica-set?

 

> kubectl describe replicaset new-replica-set

[ 해당 옵션으로 생성된 Pod의 속성을 알 수 있음 ]

 

[ 2 ] Fix the original replica set new-replica-set to use the correct busybox image.

Either delete and recreate the ReplicaSet or Update the existing ReplicaSet and then delete all PODs, so new ones with the correct image will be created.

 

> kubectl edit rs new-replica-set (Pod의 이미지 변경 완료 하지만 기존 생성된 pod를 삭제해야함)

> kubectl delete pod [이름] [이름]

 

 

3. Deployments

[ 1 ] Create a new Deploy with the below attributes using your own deployment definition file.

 

Name : httpd-frontend

Replicas : 3

Image " httpd:2.4-alpine

 

> kubectl create deployment httpd-frontend --image=httpd:2.4-alpine --replicas=3

 

 

4. Services

 

[ 1 ] Create a new service to access the web application using the service-definition-1.yaml file.

 

Name: webapp-service

Type: NodePort

targetPort: 8080

port: 8080

nodePort: 30080

selector:  name: simple-webapp

 

 

> vi service-definition-1.yaml

> kubectl create -f service-definition-1.yaml

 

 

 

5. Namespaces

 

[ 1 ] which namespace has the blue pod in it?

 

> kubectl get pods -all-namespaces / kubectl get pods -A

 

서로 다른 네임스페이스의 접근을 위해서는 Full Address를 사용해야 합니다. ex) db-service.dev.svc.cluster.local

 

 

 

6. Imperative vs Deperative

 

[ 1 ] Deploy 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

 

 

[ 2 ] 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"

 

[ 3 ] Create a service redis-service to expose the redis application within the cluster on port 6379. User Imperative

 

> kubectl expose pod redis --port 6379 --name redis-service

 

 

[ 4 ] 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.

 

> kubectl create deploy webapp --image=kodekloud/webapp-color --replicas=3

 

 

[ 5 ] Create a new pod called custom-nginx using the [nginx] image and expose it on container por 8080

 

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

 

 

[ 6 ] Create a new delpoy called redis-deploy in the dev-ns namespace with the redis image. have 2 replicas

 

> kubectl create deploy redis-deploy --image=redis --namespace=dev-ns --replicas=2

 

 

[ 7 ] Create a pod called httpd using the image httpd:alpine in the default namespace. Next, create a svc of type CluserIP by the same name (httpd). The target port for the service should be 80.

 

> kubectl run httpd --image=httpd:alpine --port=80 --expose

 

Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.