Posts

Showing posts with the label kind

Kubernetes Health Check and Auto Restart

Image
Introduction When you deploy an application to a production environment, various issues can cause it to stop working. These could be code bugs, database problems, or external service issues. Each problem requires a different solution. However, if you’re using Kubernetes to deploy your application and want it to automatically restart when an issue occurs, this article is for you. Prerequisites Before proceeding, ensure you have: A Kubernetes cluster set up. You can use Google Kubernetes Engine or set up a local Kubernetes cluster with Kind . Knowledge of Kubernetes , specifically how to create Deployments and Services . Kubernetes Probes In this article, I'll guide you through using three types of probes to check the status of your application: 1. Startup Probe    - As the name suggests, this probe runs when the application starts. It ensures the container has started successfully. Only after the Startup Probe succeeds do the Readiness and Liveness Probes execute. 2. Readin...

Kubernetes PersistentVolume and PersistentVolumeClaim to storage data

Image
Introduction In previous articles, I've guided you through using Kubernetes (K8s) to create resources from Docker images , resulting in stateless applications. This means no data is retained during usage, and restarting resources resets the application to its initial state. If you're familiar with Docker , you might know about mounting volumes to save data externally and reattach it to a Docker container as needed. In Kubernetes , you can achieve a similar result using PersistentVolume (PV) and PersistentVolumeClaim (PVC) to build stateful applications. Using PV and PVC in Kubernetes is crucial for real-world applications because they allow your data to persist across frequent deployments and restarts. Applications often face crashes or restarts due to issues, and having persistent data ensures seamless operation. PersistentVolume (PV) : A storage resource provisioned by an administrator. It exists independently of the pod lifecycle PersistentVolumeClaim (PVC) : A reques...

Kubernetes ConfigMap and Secret

Image
Introduction This article will guide you on how to use ConfigMap and Secret to pass environment variables. As you know, during software development, you need to deploy on different environments such as development, staging, and production. We aim to use the same codebase across these environments but sometimes need to pass different environment variables for specific configurations. Kubernetes (K8s) supports ConfigMap and Secret to address this need. If you've used Docker before, configuring environment variables in K8s will feel similar. ConfigMap is an object that stores data in key-value pairs, intended for non-sensitive information (i.e., values that can be displayed when viewing the configuration of K8s resources). Supported data types include number , boolean , and string (it can store a string of characters or the contents of a text file). Secret has several types, with type=Opaque being the most commonly used. It works similarly to ConfigMap but is used for sensit...

Kubernetes Horizontal Pod Autoscaling

Image
Introduction There are two common scaling methods: Vertical scaling and Horizontal scaling . Vertical scaling involves adding more hardware, such as RAM or CPU , or increasing the number of server nodes. Horizontal scaling , on the other hand, means adding more instances of an app to fully utilize the available resources on a node or server. However, horizontal scaling has its limits. Once a node's resources are maxed out, vertical scaling becomes necessary. This article will focus on horizontal scaling using Kubernetes Horizontal Pod Autoscaling (HPA) , which automatically scales resources up or down based on system demands. Implementation Process 1. Build a Docker image for your application. 2. Deploy the image using a Deployment and LoadBalancer service. 3. Configure HPA to automatically scale resources. To use HPA for auto-scaling based on CPU/Memory , Kubernetes must have the metrics-server installed. If you’re using a cloud provider, the metrics-server is usually instal...