неділя, 26 листопада 2023 р.

Kubernetes Ingress/Nginx 5. Ingress Controller

 kubectl get po -A

kubectl exec <nginx-ingress-pod> -n nginx-ingress -- cat /etc/nginx/nginx.conf


5. Ingress Controller

In our stand we use ingress-nginx Ingress controller - NGINX based image used as a reverse proxy and load balancer. The goal of this Ingress controller is the assembly of a configuration file (/etc/nginx/nginx.conf) from Ingress Resources.

In case of the need for deep troubleshooting it might require to inspect nginx’ configuration.

Let’s inspect this config file and answer several questions:

Q1 What is Nginx Ingress Controller pod name?

Q2 What is the value of proxy_connect_timeout for server_name lights.k8slab.playpit.net

Q3 what is the value of access_log configuration of “default backend”

понеділок, 20 листопада 2023 р.

Kubectl 3 Deployment 1. What is a Deployment?





Deployments represent a set of multiple, identical Pods with no unique identities. A Deployment runs multiple replicas of your application and automatically replaces any instances that fail or become unresponsive. In this way, Deployments help ensure that one or more instances of your application are available to serve user requests. Deployments are managed by the Kubernetes Deployment controller.

Deployments use a Pod template, which contains a specification for its Pods. The Pod specification determines how each Pod should look like: what applications should run inside its containers, which volumes the Pods should mount, its labels, and more.

When a Deployment’s Pod template is changed, new Pods are automatically created one at a time.

The deployment is (simply) responsible for rolling out your application, looking after its updates and rolling back to previous state - if needed. This is achieved because “Deployment” creates corresponding “Replicaset” per each deployment object:

Q1 What Deployment is currently running in milky-way namespace

Q2 How many replicaSets does this Deployment have right now?

Q3 What is Its currently active ReplicaSet Name?

Q4 Which image is used by the Application now (get rs -o wide)?

пʼятниця, 17 листопада 2023 р.

Kubernetes. 3 Deployment. 6. Deployments.

 apiVersion: apps/v1
kind: Deployment
metadata:
  name: osydor-app
  labels:
    app: osydor-app
    student: osydor
spec:
  replicas: 1
  selector:
    matchLabels:
      app: osydor-app
  template:
    metadata:
      labels:
        app: osydor-app
        deploy: osydor-app
        kind: redis
        role: master
        tier: db
    spec:
      containers:
      - name: redis-master
        image: redis:5-alpine
        ports:
        - containerPort: 6379
      initContainers:
        - command:
          - sleep
          - "10"
          image: busybox:1.34
          imagePullPolicy: IfNotPresent
          name: busybox


Create a deployment manifest file /root/osydor-app.yaml based on requirements below. And deploy it.

Requirements:

  • Deployment Name: osydor-app

  • Deployment Labels:

    • app: osydor-app
    • student: osydor
  • Pod(s) Labels:

    • deploy: osydor-app
    • kind: redis
    • role: master
    • tier: db
  • Container:

    • Image: redis:5-alpine
    • Port: 6379
    • Name: redis-master
  • Init Container:

    • Image: busybox:1.34
    • Command: sleep 10

Please Note!

Try to avoid using constructions like:

  command: [ "sh", "-c"]
  args: ["sleep 10"]

or:

  command: [ "sh", "-c", "sleep 10"]

Why?
Because sleep is a regular binary executable file which doesn’t require any shell wrappers

$ which sleep
/usr/bin/sleep

Verify:

$ kubectl get deploy osydor-app
NAME            READY   UP-TO-DATE   AVAILABLE   AGE
osydor-app   1/1     1            1           17s

$ kubectl get pod -l deploy=osydor-app
NAME                             READY   STATUS    RESTARTS   AGE
osydor-app-57479f67bc-nkdk7   1/1     Running   0          23s

$ cat << EOF | tr '\n' ',' | sed 's/,$//;s/ *//g' | \
xargs -IF kubectl get pod -l deploy=osydor-app -o custom-columns="F"
  STATUS:.status.phase
  CONT_IMAGE:.spec.containers[*].image
  CONT_NAME:.spec.containers[*].name
  CONT_PORT:.spec.containers[*].ports[*].containerPort
  INITC_IMAGE:.spec.initContainers[*].image
  INITC_CMD:.spec.initContainers[*].command
  INITC_ARGS:.spec.initContainers[*].args
  NAME:.metadata.name
EOF
STATUS    CONT_IMAGE       CONT_NAME      CONT_PORT   INITC_IMAGE    INITC_CMD    INITC_ARGS   NAME
Running   redis:5-alpine   redis-master   6379        busybox:1.34   [sleep 10]   <none>       osydor-app-57479f67bc-nkdk7

Documentation:

Check Report

osydor-app deployment:

deployment created

deployment labels are ok

Pod template:

pod labels are ok

Pod Container:

image is ok

port is ok

container name is ok

Pod InitContainer:

image is ok

command is ok

Score: 100


 

четвер, 16 листопада 2023 р.

Kubernetes. 3 Deployment 3. Creating Deployment. Quick Way

 apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: easy-peasy
  name: easy-peasy
spec:
  replicas: 5
  selector:
    matchLabels:
      app: easy-peasy
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: easy-peasy
    spec:
      containers:
      - command:
        - sleep
        - infinity
        image: busybox:1.34
        name: busybox
        resources: {}
status: {}

 

Please inspect following command:


kubectl create deployment --help


Create a deployment with the specified name.


Aliases:

deployment, deploy


Examples:

  # Create a deployment named my-dep that runs the busybox image.

  kubectl create deployment my-dep --image=busybox:1.34

  

  # Create a deployment with command

  kubectl create deployment my-dep --image=busybox -- date

  

  # Create a deployment named my-dep that runs the nginx image with 3 replicas.

  kubectl create deployment my-dep --image=nginx --replicas=3

  

  # Create a deployment named my-dep that runs the busybox image and expose port 5701.

  kubectl create deployment my-dep --image=busybox --port=5701


Options:

      --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or

map key is missing in the template. Only applies to golang and jsonpath output formats.

      --dry-run='none': Must be "none", "server", or "client". If client strategy, only print the

object that would be sent, without sending it. If server strategy, submit server-side request

without persisting the resource.

      --field-manager='kubectl-create': Name of the manager used to track field ownership.

      --image=[]: Image names to run.

  -o, --output='': Output format. One of:

json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-as-json|jsonpath-file.

      --port=-1: The port that this container exposes.

  -r, --replicas=1: Number of replicas to create. Default is 1.

      --save-config=false: If true, the configuration of current object will be saved in its

annotation. Otherwise, the annotation will be unchanged. This flag is useful when you want to

perform kubectl apply on this object in the future.

      --template='': Template string or path to template file to use when -o=go-template,

-o=go-template-file. The template format is golang templates

[http://golang.org/pkg/text/template/#pkg-overview].

      --validate=true: If true, use a schema to validate the input before sending it


Usage:

  kubectl create deployment NAME --image=image -- [COMMAND] [args...] [options]


Use "kubectl options" for a list of global command-line options (applies to all commands).


Task:


Inspect the details listed above, add necessary options to kubectl create deploy command to produce following deployment configuration:


    Name: easy-peasy

    Image: busybox:1.34

    Replicas: 5

    Command: sleep infinity


Take into Account:


To generate Deployment manifest you should use the same command with these options:


    --dry-run=client

    -o yaml


    Make sure you use these options before command part (-- ...)


Documentation:


    https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

    https://cloud.google.com/kubernetes-engine/docs/concepts/deployment


Check Report


easy-peasy deployment:


✓ created


✓ image is ok


✓ replicas set to correct value


✓ all pods are up


✓ command is ok


Score: 100


 

середа, 15 листопада 2023 р.

Kubernetes. Pods. 5. Getting Pod Details

key command to this task kubectl get pods -n wonderland  -o wide --sort-by=.status.podIP > /to_check/wonderland-pods.txt


  Task:

Should we know where our pod is running on (node name) or its IP address, the most easiest way is to get “extended” details with wide output format.

Please get all pods (from wonderland ns) details in wide format and save it into /to_check/wonderland-pods.txt on client host

Useful Command:

Getting Pods:

kubectl get \
  ${RESOURCE_TYPE} \
  ${RESOURCE_NAME} \
  --namespace ${NS_NAME} \
  -o wide

Sorting by IP Address:

kubectl get pods -o wide --sort-by=.status.podIP

Documentation:

Complete the task and answer the questions below:

Q1 Which pod (from the task above) running on node02 has the lowest IP Address?

Q2 And it’s IP address is

Check Report :

Report file (/to_check/wonderland-pods.txt):

is found

file contains correct data

Score: 100

What about Quiz?

Kubernetes. Pods. 3. Init Containers

key command for this task  kubectl describe pods moc-turtle-b77d5466f-ztnb3 -n wonderland



A Pod can have multiple containers running apps within it, also it can have one or more init containers, which run before the app containers start.

We use init containers for running some stuff before main container starts.

Init containers are exactly like regular containers, except:

  • Init containers always run to completion.
  • Each init container must complete successfully before the next one starts.

Pod Template:

apiVersion: v1
kind: Pod
metadata:
  name: <pod name>
  ...
spec:
  initContainers:
  - name: <init container name
    image: <init container image>
    <other parameters>
  ...
  containers:
  - name: <container name>
    image: <container inage>
    <other parameters>
  ...
  <other parameters>

If a Pod’s init container fails, Kubernetes repeatedly restarts the Pod until the init container succeeds. However, if the Pod has a restartPolicy of Never, Kubernetes does not restart the Pod.

Use Cases for Init Container:

  • In Jenkins Pod, init container can preconfigure main Jenkins application (regular container): install plugins, configure settings, update. Once it’s done, regular container start with prepared configuration
  • Init container can fetch encrypted secrets from a vault and write to file system
  • Init Container can block app startup until another system is available (i.e., a queue or database server)
  • Dynamic data fetched from a database and cached for the app to run after startup

Documentation:

Task:

Inspect wonderland namespace and answer the questions below

Q1 There’s a pod with initContainer. What is its name?

Q2 What is the name of this initContainer?

Q3 What is its IP address?




вівторок, 14 листопада 2023 р.

Kubernetes. Basics. 9. Creating a Pod

 


Creating Pods

Pod manifest file (pod.yaml):

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: pod-label
  name: pod-name
spec:
  containers:
  - image: pod-image
    name: pod-main-container-name

Apply pod manifest:

$ kubectl apply -f pod.yaml

Task:

There’s a file /opt/practice/web-pod.yaml. Investigate and deploy it.

Once it’s done, please answer the questions below

Quiz:

Q1 What is the name of this Pod?

Q2 What is the name of the container in this Pod?

Q3 What is the namespace where this Pod is running?