Posts

Showing posts from May, 2022

Kubernetes - Volumes

Image
  Persistent volume (PV) is a piece of storage provided by an administrator in a Kubernetes cluster. When a developer needs persistent storage for an application in the cluster, they request that storage by creating a persistent volume claim (PVC) and then mounting the volume to a path in the pod Once that is done, the pod claims any volume that matches its requirements (such as size, access mode, and so on).  An administrator can create multiple PVs with different capacities and configurations.  It is up to the developer to provide a PVC for storage, and then Kubernetes matches a suitable PV with the PVC.  If there is no PV to match the PVC, the StorageClass dynamically creates a PV and binds it to the PVC.  It is important to note that Kubernetes does not restrict PVs to a namespace, which means that a pod in any namespace can claim a PV for storage. I am trying to create a pod with volume. But not creating a volume at first sight.  root@master:/kube# kub...

Kubernetes - Blue/Green Deployment

Image
This deployment is widely used across the companies. Its based on ACTIVE/PASSIVE concept. We are going to create a deployment with the image - rajasekar/node-web-v1 of 3 replicas and bind to a service IP. Next, We are going to create another deployment with the image rajasekar/node-web-v2 and enable this deployment in the service IP - aka IP cutover. Make a note of the labels I am using in the deployment: app: nodejs and version: "1.0" apiVersion: apps/v1 kind: Deployment metadata:   name: node-app-v1   labels:     app: node-app spec:   replicas: 3   selector:     matchLabels:       app: nodejs       version: "1.0"   template:     metadata:       labels:         app: nodejs         version: "1.0"     spec:       containers:       - name: nodejs-v1         image: rajasekar/node-web-v1:latest...

Kubernetes - Building NodeJS Application and deployment - Recreate Strategy

Image
  Now we'll build a simple Node.js web application and package it into a container image.  The application will accept HTTP requests and respond with the hostname of the machine it's running in. root@masterk8s:/kube# mkdir nodejs root@masterk8s:/kube# cd nodejs/ root@masterk8s:/kube/nodejs# vi app.js root@masterk8s:/kube/nodejs# cat app.js const http = require('http'); const os = require('os'); console.log("My server starting and listening on 8080..."); var handler = function(request, response) {   console.log("Received request from " + request.connection.remoteAddress);   response.writeHead(200);   response.end("You've hit " + os.hostname() + "\n"); }; var www = http.createServer(handler); www.listen(8080); root@masterk8s:/kube/nodejs# It starts up an HTTP server on port 8080. The server responds with an HTTP response status code 200 OK and the text "You've hit <hostname>" to every request.  The re...