CKA - Core Concepts

임상규·2024년 1월 30일
1

Kubernetes

목록 보기
8/19
post-thumbnail

PODs

1

How many pods exist on the system?

In the current(default) namespace.
$ k get pods

2

Create a new pod with the nginx image.
$ k run nginx --image=nginx

3

How many pods are created now?
$ k get pods

4

What is the image used to create the new pods?
$ k describe pods | grep -i image

5

Which nodes are these pods placed on?
$ k get pods -o wide

6

How many containers are part of the pod webapp?
$ k get pod webapp

7

What images are used in the new webapp pod?
$ k describe pod webapp | grep -i image

8

What is the state of the container agentx in the pod webapp?
$ k describe pod webapp | grep -iB 10 agentx

9

Why do you think the container agentx in pod webapp is in error?
Failed to pull image "agentx": rpc error: code = Unknown desc = failed to pull and unpack image "docker.io/library/agentx:latest": failed to resolve reference "docker.io/library/agentx:latest": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

10

What does the READY column in the output of the kubectl get pods command indicate?
Running Containers in POD/Total Containers in POD

11

Delete the webapp Pod.
$ k delete pod webapp

12

Create a new pod with the name redis and the image redis123.
$ k run redis --image=redis123

13

Now change the image on this pod to redis
$ k edit pod red

image: redis

ReplicaSets

1

How many PODs exist on the system?

In the current(default) namespace.
$ k get pods

2

How many ReplicaSets exist on the system?

In the current(default) namespace.
$ k get rs

3

How about now? How many ReplicaSets do you see?
$ k get rs

4

How many PODs are DESIRED in the new-replica-set?
$ k get rs

5

What is the image used to create the pods in the new-replica-set?
$ k describe rs new-replica-set | grep -i image

6

How many PODs are READY in the new-replica-set?
$ k get rs

7

Why do you think the PODs are not ready?
Failed to pull image "busybox777": rpc error: code = Unknown desc = failed to pull and unpack image "docker.io/library/busybox777:latest": failed to resolve reference "docker.io/library/busybox777:latest": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

8

How many PODs exist now?
$ k get pods

9

Why are there still 4 PODs, even after you deleted one?
ReplicaSet ensures that desired number of PODs always run

10

Create a ReplicaSet using the replicaset-definition-1.yaml file located at /root/.

There is an issue with the file, so try to fix it.
replicaset-definition-1.yaml

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: replicaset-1
spec:
  replicas: 2
  selector:
    matchLabels:
      tier: frontend
  template:
    metadata:
      labels:
        tier: frontend
    spec:
      containers:
      - name: nginx
        image: nginx
        
$ k apply -f replicaset-definition-1.yaml

11

Fix the issue in the replicaset-definition-2.yaml file and create a ReplicaSet using it.
replicaset-definition-2.yaml

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: replicaset-2
spec:
  replicas: 2
  selector:
    matchLabels:
      tier: frontend
  template:
    metadata:
      labels:
        tier: frontend
    spec:
      containers:
      - name: nginx
        image: nginx
        
$ k apply -f replicaset-definition-2.yaml

12

Delete the two newly created ReplicaSets - replicaset-1 and replicaset-2
$ k delete rs replicaset-1 && k delete rs replicaset-2

13

Fix the original replica set new-replica-set to use the correct busybox image.
$ k edit rs new-replica-set

replicas: 0
image: busybox
---------------
replicas: 4
image: busybox

14

Scale the ReplicaSet to 5 PODs.
$ kubectl scale rs new-replica-set --replicas=5

15

Now scale the ReplicaSet down to 2 PODs.
$ kubectl scale rs new-replica-set --replicas=2

Deployments

1

How many PODs exist on the system?

In the current(default) namespace.
$ k get pods

2

How many ReplicaSets exist on the system?

In the current(default) namespace.
$ k get rs

3

How many Deployments exist on the system?

In the current(default) namespace.
$ k get ds

4

How many Deployments exist on the system now?
$ k get deploy

5

How many ReplicaSets exist on the system now?
$ k get rs

6

How many Pods exist on the system now?
$ k get pods

7

Out of all the existing PODs, how many are ready?
$ k get pods

8

What is the image used to create the pods in the new deployment?
$ k describe deploy frontend-deployment | grep -i image

9

Why do you think the deployment is not ready?
Failed to pull image "busybox888": rpc error: code = Unknown desc = failed to pull and unpack image "docker.io/library/busybox888:latest": failed to resolve reference "docker.io/library/busybox888:latest": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

10

Create a new Deployment using the deployment-definition-1.yaml file located at /root/.

There is an issue with the file, so try to fix it.
deployment-definition-1.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-1
spec:
  replicas: 2
  selector:
    matchLabels:
      name: busybox-pod
  template:
    metadata:
      labels:
        name: busybox-pod
    spec:
      containers:
      - name: busybox-container
        image: busybox888
        command:
        - sh
        - "-c"
        - echo Hello Kubernetes! && sleep 3600
        
$ k apply -f deployment-definition-1.yaml

11

Create a new Deployment with the below attributes using your own deployment definition file.


Name: httpd-frontend;
Replicas: 3;
Image: httpd:2.4-alpine
$ cp deployment-definition-1.yaml httpd-frontend.yaml

httpd-frontend.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd-frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      name: httpd-frontend
  template:
    metadata:
      labels:
        name: httpd-frontend
    spec:
      containers:
      - name: httpd-frontend-container
        image: httpd:2.4-alpine

$ k apply -f httpd-frontend.yaml

Namespaces

1

How many Namespaces exist on the system?
$ k get ns

2

How many pods exist in the research namespace?
$ k get pods -n research

3

Create a POD in the finance namespace.

Name: redis
Image name: redis
$ k run redis --image=redis -n finance

4

Which namespace has the blue pod in it?
$ k get pods -A -o wide | grep -i blue

Services

1

How many Services exist on the system?
$ k get svc

2

What is the type of the default kubernetes service?
$ k describe svc kubernetes | grep -i type

3

What is the targetPort configured on the kubernetes service?
$ k describe svc kubernetes | grep -i targetport

4

How many labels are configured on the kubernetes service?
$ k describe svc kubernetes | grep -iA 10 label

5

How many Endpoints are attached on the kubernetes service?
$ k describe svc kubernetes | grep -iA 5 endpoint

6

How many Deployments exist on the system now?
$ k get deploy

7

What is the image used to create the pods in the deployment?
$ k describe deploy simple-webapp-deployment | grep -i image

8

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
service-definition-1.yaml

apiVersion: v1
kind: Service
metadata:
  name: webapp-service 
  namespace: default
spec:
  ports:
  - nodePort: 30080
    port: 8080
    targetPort: 8080
  selector:
    name: simple-webapp
  type: NodePort
  
$ k apply -f service-definition-1.yaml

Imperative Commands

1

Deploy a pod named nginx-pod using the nginx:alpine image.

Use imperative commands only.
$ k run nginx-pod --image=nginx:alpine

2

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

Use imperative commands.
$ k run redis --image=redis:alpine -l tier=db

3

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

Use imperative commands.
$ k 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.
$ k 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 port 8080
$ k run custom-nginx --image=nginx --port=8080

6

Create a new namespace called dev-ns.

Use imperative commands.
$ k create ns dev-ns

7

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 deploy redis-deploy -n dev-ns --image=redis --replicas=2

8

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.
$ k run httpd --image=httpd:alpine
$ k expose pod httpd --port 80
profile
Cloud Engineer / DevOps Engineer

0개의 댓글