Posts

Showing posts with the label kubectl

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...

Using Kubernetes Ingress to navigate traffic to Services

Image
Introduction In the previous article, I introduced the basic concepts of Kubernetes Ingress , and how to use Ingress along with related components ( Nginx Ingress Controller and cert-manager ) to automatically issue TLS certificates when deploying HTTPS applications . In this article, I'll show you how to define rules in Ingress to route traffic to different Services based on your needs. Prepare Docker Image First, you'll need a Docker image to get started. You can either use two different Docker images or follow my next instructions to prepare a Docker image . Here's a code block to create a NodeJS server that displays a title based on an environment variable input: import express from 'express' const port = 3000 const title = 'This is NodeJS Typescript Application' const app = express () app . get ( '/' , ( _ , res ) => { res . send (( process ?. env ?. TITLE ?? title ) + '! Current time is ' + Date . now ()) ...