Kubernetes Concepts

Jun 1, 2024

This writing is about my learning with kubernetes. This blog might be a quick look for my day to day uses with kubernetes. Hope you like it 🤌

Kubernetes Workload

  • An app in k8
  • Pod is atomic workload
  • Replicaset
  • Deployment
  • StatefulSet
  • DeamonSet
  • Task that run to completion
    • Job
    • CronJob
> kubectl get all
> We can ssh into kubernetes node

Kubernetes Pods

  • App is in docker hub as docker image
  • Kubernetes cluster is already setup

Pod

  • Is a single instance of an application
  • Smallest object that can be created in Kubernetes
  • Has 1:1 relationship with your application (mostly)

Multi-container pods

  • Helper container like scenario
  • When we want to keep up
  • Same network space and localhost connection and the same storage space.

To deploy container

# kubectl running nginx pod simple
kubectl run nginx —image nginx

# get the status of all the pods in the system
kubectl get pods

Minikube Workshop

### MINIKUBE DEMO

# Create a deployment
kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.10

# To get all the deployments
kubectl get deployments

# Expose deployment uisng nodeport --port=8000
kubectl expose deployment hello-minikube --type=NodePort --port=8080
service/hello-minikube exposed

Pod Workshop

### Pods Workshop

# requires imge to use it
kubectl run nginx --image=nginx

# kubectl get pods to get the  pods
kubectl get pods

Untitled

Untitled

Containers will be creating to created state

Untitled


kubectl describe pod <pod_name> # is more detailed compared to get pod
  • Learn more about describe

    • Events
      • All the events which ran after the creation of pod
    • Containers

    Untitled

Making pod using YAML in kubernetes

Untitled

## This must be named pod-defination.yml file

apiVersion: v1 # Version of kubernetes api # Depends upon which we want to make
kind: Pod # POD, Service, ReplicaSet, Deployment
metadata:
  name: myapp-pod
  labels: # custom keyvalue pair put any thing you want
  app: myapp
  type: front-end
spec:
  containers:
    - name: nginx-container
      image: nginx # name of docker image in image repo

Kubernetes ReplicationControllers and ReplicaControlSet

  • To run more than one pod in the node.
  • Ensures that the required setup is met for number of pods
  • For load balancing and Scaling

Replication Controller vs Replica set

Replication Controller:

  • older tech
  • replaced by replica set

Untitled

Kubernetes Replicasets[ In depth ]

  • Primary method of managing pod replicas and their lifecycle to provide self-healing capabilities
  • Their job is to always ensure the desired number of pods are running

Untitled

Untitled

# Replication Controller

apiVersion: v1
kind: ReplicationController
metadata:
  name: myapp-rc
  labels:
    app: myapp
    type: front-end
spec:
  replicas: 3

  template:        # As same as for pod
    metadata:
      name: myapp-pod
      labels:
        app: myapp
    spec:
      containers:
      - name: nginx-container
        image: nginx
# Replication-set Controller

apiVersion: apps/v1
kind: ReplicationController
metadata:
  name: myapp-rc
  labels:
    app: myapp
    type: front-end
spec:
  replicas: 3
  selector:        # major difference
		 matchLabels:
		   type: myapp # matching the myapp

  template:        # As same as for pod
    metadata:
      name: myapp-pod
      labels:
        app: myapp
    spec:
      containers:
      - name: nginx-container
        image: nginx

Kubernetes Deployment

Untitled

  • For production
  • For updates: Blue green, Rolling, Rollback etc
  • Object higher than replica-set
  • Create on template for each microservice

Untitled

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:

  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

  replicas: 3
  selector:
    matchLabels:
      app: nginx

Untitled

Updates

  • Changes replicaset from 5 to 0 in old version
  • Changes replicaset from 0 to 5 in new version
  • And vice versa in rollback

Kubernets DaemonSet

  • Ensure all nodes (or a subset) run an instance of a Pod
  • Scheduled by the scheduler controller and run by the daemon controller
  • As nodes are added to the cluster, Pods are added to them
  • Typical uses
    • Running a cluster storage daemon
    • Running a logs collection daemon on every node
    • Running a node monitoring daemon on every node

Untitled

Untitled


Kubernetes StatefulSet

  • For Pods that must persist or maintain state

Untitled

Untitled

Untitled

Untitled


Kubernetes Networking

  • Kubernetes doesn’t setup any networking for us
  • We should setup networking ourself
  • KUBERNETES EXPTECTS THIS
    • All PODs can communicate to one another without NAT
    • All nodes can communicate with al containers and vice versa without NAT

Kubernetes Services

  • Services enables connectivity between various parties
  • Loose coupling between microservices
  • Connection between FE to BE, Users to FE, etc

Untitled

NodePort

  • Listens to the port and forwards it to node port

ClusterIP


Kubernetes Namespaces

Untitled

Untitled

Untitled

Untitled

Untitled


Kubernetes Job

Untitled

Untitled

Untitled

Cronjob In UTC

Untitled

Untitled


Storage and Persistent volume data

Volumes

Untitled

Storage - Static Way

  • Persistent Volumes
    • Represnts a storage resource
    • Cluster wide
    • Provisoned by an admin
  • Persistent Volume Claim
    • A one to one mapping to persistent volume
  • One or more pods can use a persistent volume Claom
  • Can be consumed by any of the conatiners within the pod

Untitled

Drawback

  • Can lead to waste of resources

Persistent volumes and claims

Untitled

Untitled

Untitled

Reclaim Policies

  • Delete
    • Delete the data upon pods deletion
    • The default
  • Retain
    • Keeps the data upon pods deletion

Untitled


Kubernetes ConfigMaps

Untitled

Untitled

Untitled

Untitled

Untitled


Kubernetes Secrets

Untitled

Untitled

Untitled

Untitled


Kubernetes Observability - Probes

Untitled

Untitled

Untitled


Kubernetes HPA

Untitled

Untitled


Related Posts

backend

Every Class in NestJS and Its Functionalities

NestJS is a huge framework built on top of TypeScript, JavaScript also uses Express or Fasitfy as an underlying mechanism to route requests.
Every Class in NestJS and Its Functionalities

You many also like

tips and tricks

I Bet You Don’t Use These JavaScript Tricks and Practices

Tell me how many did you know by responding to the article and you may share this with your network to find out how many they know.
I Bet You Don’t Use These JavaScript Tricks and Practices
backend

Take Your Django Serializer Game to the Next Level

Django has always been a quick go to framework that I mostly use when I need some result quickly. Start with the server or when I want to set up a quick server.
Take Your Django Serializer Game to the Next Level
devops

Kubernetes Concepts

This writing is about my learning with kubernetes. This blog might be a quick look for my day to day uses with kubernetes.
Kubernetes Concepts
database

Eat the frog: MongoDB Design Patterns

Here are some of the few design patterns that you can use to better your MongoDB schema, so you’ll keep your team happy and yourself happier.
Eat the frog: MongoDB Design Patterns
About Me
Contact
server

Nirjal Paudel