Understanding Pods, Nodes, Deployments and Services

Pods and nodes are both fundamental concepts in the Kubernetes architecture, but they serve different purposes. A pod is the smallest deployable unit in Kubernetes, representing a single instance of a running process in a cluster. A pod can contain one or more tightly-coupled containers that share the same network namespace and storage volumes. All containers in a pod run on the same node, and they can communicate with each other using local host networking. ...

September 13, 2024 · 12 min

Pod Session Management with Redis

Consider a huge monolith application which is running on a single EC2 and you want to swap it into the microservices architecture. From the infra perspective, you have to setup cluster with a namespace for these microservices and associate pods as applications to run in. Now as pods are running, it how do you manage user sessions? Let’s say if a pod gets deleted somehow, the user will be signed out of the application which you do not want to happen. ...

September 13, 2024 · 2 min

Pod Preemption Priority

pod priority via their yaml - preemptionPolicy: PreemptLowerPriority priority: 0 https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/ Priority class - non-namespaced object that defines a mapping from a priority class name to the integer value of the priority. They are used to prioritize pods to be scheduled before and come with apiVersion: scheduling.k8s.io/v1 kind: PriorityClass metadata: name: high-priority value: 1000000 globalDefault: false description: "This priority class should be used for XYZ service pods only." (preemptionPolicy: PreemptLowerPriority is default) Non-preempting class example - apiVersion: scheduling.k8s.io/v1 kind: PriorityClass metadata: name: high-priority-nonpreempting value: 1000000 preemptionPolicy: Never globalDefault: false description: "This priority class will not cause other pods to be preempted." Pod with priority-class ...

September 13, 2024 · 3 min

Kubernetes Design Patterns

Multi-container design patterns Sidecar pattern An extra container in your pod to enhance or extend the functionality of the main container. Ambassador pattern A container that proxy the network connection to the main container. Adapter pattern A container that transform output of the main container. Reference - https://kubernetes.io/blog/2015/06/the-distributed-system-toolkit-patterns/ The idea for a sidecar container is to add some functionality not present in the main container. Rather than bloating code, which may not be necessary in other deployments, adding a container to handle a function such as logging solves the issue, while remaining decoupled and scalable. Prometheus monitoring and Fluentd logging leverage sidecar containers to collect data. ...

September 13, 2024 · 2 min

Kubernetes Volumes Deep Dive

References https://stackoverflow.com/questions/45511339/kubernetes-minikube-with-local-persistent-storage https://platform9.com/blog/tutorial-dynamic-provisioning-of-persistent-storage-in-kubernetes-with-minikube/ https://stackoverflow.com/questions/66355331/deployment-cannot-find-pvc-on-minikube minikube supports hostPath mount out of box - minikube mount D:/vscode/devops:/usr/volume kubectl api-resources --namespaced=false # returns resources which are cluster-wide kubectl api-resources --namespaced=true # resources which are ns scoped PVCs request from storage classes - https://kubernetes.io/docs/concepts/storage/storage-classes/ PVC are ns scoped so 2 pvc can have same name if in different ns. for minikube generate another storage class as classic uses a specific path Setting up own PV and VPC For creating own pv, pvc you need to create a storage class as well as only then it will use the pv you creted otherwise will create dynamic allocation. ...

September 13, 2024 · 10 min

Deployments and Replicasets

Both Deployments and ReplicaSets are designed to manage stateless applications in Kubernetes. This means that they are not responsible for managing any application state or data storage. Instead, they manage the deployment and scaling of stateless pods that run the application code. In a stateless application, each pod is independent and interchangeable, and can be scaled up or down as needed. The application state is typically stored in a separate data store, such as a database, that is managed independently of the pods. ...

August 25, 2024 · 2 min

MongoDB StatefulSet Setup

Creating a MongoDB Replica Set with authentication using StatefulSets involves several steps. Below is a manifest example for deploying a MongoDB Replica Set with authentication using StatefulSets in Kubernetes. This assumes you have a Kubernetes cluster set up and kubectl configured. Create a Secret for MongoDB Authentication: Create a Kubernetes Secret to store the MongoDB admin credentials. You can encode the username and password using echo -n 'yourpassword' | base64: ...

July 11, 2024 · 2 min