본문 바로가기
cloud/k8s(문제풀이)

[cka] kodekloud - IMPERATIVE COMMANDS

by mozi2 2022. 6. 7.
반응형

이번에는  IMPERATIVE 관련해서 공부해보겠습니다. 

 

1.In this lab, you will get hands-on practice with creating Kubernetes objects imperatively.

 

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.

 

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

# k run nginx-pod --image=nginx:alpine

A) check

 

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

# k run redis --image=redis:alpine --dry-run=client -o yaml > redis.yaml

 : 기본적인 설정으로 파일을 만든 후에 tier 옵션은 vi 가서 직접 변경한다. 

 

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

# k create svc clusterip redis-service --tcp=6379:6379

  : 순서는 service, type, port 순서대로

  : 순서를 변경해서했을 때 생성되지 않음

 

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

#  k create deployment webapp --image=kodekloud/webapp-color --replicas=3

# k get deployments.apps

6. Create a new pod called custom-nginx using the nginx image and expose it on container port 8080.

# k run custom-nginx --image=nginx --port=8080

7. Create a new namespace called dev-ns. Use imperative commands.

# k create namespace dev-ns

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

# k create deployment redis-deploy -n dev-ns --image=redis --replicas=2

# k get deployments.app

9.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?

# k run httpd --image=http:alpine --port=80 --expose

# k get pods

# k get svc 

 

728x90
반응형

'cloud > k8s(문제풀이)' 카테고리의 다른 글

[cka]kodekloud - Labels & selectors  (0) 2022.06.08
[cka] kodekloud-scheduling  (0) 2022.06.08
[cka]kodekloud-services  (0) 2022.06.07
[cka] kodekloud-namespaces  (0) 2022.06.07
[cka]kodekloud-Deployments  (0) 2022.06.07