Giter Club home page Giter Club logo

k8s-labs-2-to-4's Introduction

K8S-LABS

K8S LAB 2

1-Create a ReplicaSet using the below yaml

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: new-replica-set
  namespace: default
spec:
  replicas: 4
  selector:
    matchLabels:
      name: busybox-pod
  template:
    metadata:
      labels:
        name: busybox-pod
    spec:
      containers:
      - command:
        - sh
        - -c
        - echo Hello Kubernetes! && sleep 3600
        image: busybox777
        imagePullPolicy: Always
        name: busybox-container
#Create a YAML file then apply it
vim deployment-1.yml
kubectl apply -f deployment-1.yml

Screenshot from 2023-01-13 18-25-39

2-How many PODs are DESIRED in the new-replica-set?

kubectl get replicaset.apps

Screenshot from 2023-01-13 18-29-42

3-What is the image used to create the pods in the new-replica-set?

the image is busybox777

kubectl describe replicaset.apps

Screenshot from 2023-01-13 18-32-54

4-How many PODs are READY in the new-replica-set?

kubectl get replicaset.apps

Screenshot from 2023-01-13 18-34-36

5-Why do you think the PODs are not ready?

I think the PODS are not ready due to an error in fetching the image from container registery which is DockerHub (no such image called busybox777)

kubectl describe replicaset.apps #OR
kubectl get pods

Screenshot from 2023-01-13 18-42-31 Screenshot from 2023-01-13 18-43-16

6-Delete any one of the 4 PODs.

How many pods now

still 4 pods due to specified desired number of pods

kubectl delete po new-replica-set-69bsf

Screenshot from 2023-01-13 18-44-08

7-Why are there still 4 PODs, even after you deleted one?

Because of the controller on master node checks the worker node for the specified desired number of pods in the YAML file of deployment if there's any pod down for any reason it automatically creates another one

8-Create a ReplicaSet using the below yaml

There is an issue with the file, so try to fix it.

apiVersion: 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

The issue in the YAML file is the apiVersion the apiVersion of Replica sets is apps/v1

the right answer is

apiVersion: apps/v1

Edited the file and applied it, now the Deployment is running Screenshot from 2023-01-13 18-49-58

K8S LAB 3

1-Create a deployment called my-first-deployment of image nginx:alpine in the default namespace.

Check to make sure the deployment is healthy.

kubectl create deployment my-first-deployment --image=nginx:alpine --dry-run=client -oyaml > dep1.yml
kubectl apply -f dep1.yml

Screenshot from 2023-01-14 16-38-31

2-Scale my-first-deployment up to run 3 replicas. Check to make sure all 3 replicas are ready.

kubectl scale deployment my-first-deployment --replicas=3
#OR best practice is modify the Yaml file itself to make replicas 3

Screenshot from 2023-01-14 13-13-47

3-Scale my-first-deployment down to run 2 replicas.

kubectl scale deployment my-first-deployment --replicas=2
#OR best practice is modify the Yaml file itself to make replicas 2

Screenshot from 2023-01-14 13-14-34

4-Change the image my-first-deployment runs from nginx:alpine to httpd:alpine .

vim dep1.yml 
#change the image
kubectl apply -f dep1.yml

Screenshot from 2023-01-14 13-17-19

Screenshot from 2023-01-14 13-17-05

5-Delete the deployment my-first-deployment

kubectl delete deployment my-first-deployment  

Screenshot from 2023-01-14 13-20-27

6-Create deployment from the below yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend-deployment
  namespace: default
spec:
  replicas: 4
  selector:
    matchLabels:
      name: busybox-pod
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        name: busybox-pod
    spec:
      containers:
      - command:
        - sh
        - -c
        - echo Hello Kubernetes! && sleep 3600
        image: busybox888
        imagePullPolicy: Always
        name: busybox-container
vim dep2.yml
kubectl apply -f dep2.yml

Screenshot from 2023-01-14 13-29-00

7-How many ReplicaSets exist on the system now?

kubectl get deployment

6 total replica sets

Screenshot from 2023-01-14 13-32-14

8-How many PODs exist on the system now?

kubectl get pods 

6 pods

9-Out of all the existing PODs, how many are ready?

2 pods Are ready

10-What is the image used to create the pods in the new deployment?

kubectl describe deployment

busybox888 image Screenshot from 2023-01-14 13-34-38

11-Why do you think the deployment is not ready?

Error pulling the image from docker hub, No such image.

12-Create a new Deployment using the below yaml

No YAML file was provided

13- There is an issue with the file, so try to fix it and correct the value of kind.

The issue is there is no Yaml file included :'D

LAB 4

1-How many Services exist on the system?

kubectl get svc

Screenshot from 2023-01-14 13-57-37

2-What is the type of the default kubernetes service?

The Default type is ClusterIP

Screenshot from 2023-01-14 13-57-37

3-What is the targetPort configured on the kubernetes service?

kubectl describe svc

target port is 6443/TCP

Screenshot from 2023-01-14 13-59-07

4-How many labels are configured on the kubernetes service?

Labels:            component=apiserver
                   provider=kubernetes

Screenshot from 2023-01-14 13-59-07

5-How many Endpoints are attached on the kubernetes service?

1 Endpoint = 172.30.1.2:6443

6-Create a Deployment using the below yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: simple-webapp-deployment
  namespace: default
spec:
  replicas: 4
  selector:
    matchLabels:
      name: simple-webapp
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        name: simple-webapp
    spec:
      containers:
      - image: kodekloud/simple-webapp:red
        imagePullPolicy: IfNotPresent
        name: simple-webapp
        ports:
        - containerPort: 8080
          protocol: TCP
          
vim deployment.yml
kubectl apply -f deployment.yml

7-What is the image used to create the pods in the deployment?

kubectl describe deployment

kodekloud/simple-webapp:red

Screenshot from 2023-01-14 14-04-38

8-Create a new service to access the web application using the the below

Name: webapp-service
Type: NodePort
targetPort: 8080
port: 8080
nodePort: 30080

The syntax of this Yaml file is wrong and it's missing key components

The updated version :

Screenshot from 2023-01-14 14-15-56

vim scv.yml
kubectl apply -f scv.yml

Thank You !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.