Working with Namespaces And Launching your Kubernetes Cluster with Deployment

Working with Namespaces And Launching your Kubernetes Cluster with Deployment

What are Namespaces and Services in k8s:

In the world of Kubernetes (k8s), Namespaces and Services play important roles in simplifying and organizing the chaos of managing multiple applications. Think of a Namespace as a virtual playground or city district where you can group and isolate various applications, preventing them from interfering with each other. It's like having different neighborhoods for different activities.

Now, imagine Services as post offices in each of these neighborhoods. They make communication between applications seamless, just like how you send letters or packages to different addresses. A Service ensures that when one application in a Namespace wants to talk to another, it can do so without any confusion or getting lost in the vast Kubernetes city.

For a funny analogy, let's say your applications are like quirky characters living in different theme parks within the Kubernetes universe. Namespaces are the theme parks themselves, keeping the roller coasters separate from the petting zoos. Services are the communication stations, like talking giraffes or walkie-talkie penguins, making sure all characters can exchange information smoothly without causing a commotion in their respective parks.

In simpler terms, Namespaces organize, and Services facilitate communication—helping your applications live harmoniously in the Kubernetes amusement park without causing any mayhem or getting tangled in their virtual roller coaster tracks.

What is Deployment in k8s:

Let's dive into the whimsical world of Kubernetes and unravel the concept of Deployments! In this tech realm, a Deployment is like a magical spell for managing your applications. Imagine you're the master wizard overseeing a bustling bakery in a fantastical town.

Now, each day, you conjure up a new batch of enchanted cupcakes (your application) to meet the townspeople's cravings. Here's where the Kubernetes spellbook comes into play. A Deployment is your spell – it ensures that the cupcakes are not only freshly baked but also spread across the town consistently, maintaining order and keeping the bakery running smoothly.

Picture this: your magical recipe book (Kubernetes Deployment) specifies how many cupcakes should be baked, how they should look, and where they should be delivered. If, for instance, a pesky dragon (unexpected issue) swoops in and devours a cupcake stand, the Deployment magic kicks in. It notices the loss and swiftly replicates another stand to ensure the cupcakes keep flowing, preventing chaos in the bakery kingdom.

In non-tech terms, a Kubernetes Deployment is like having a magical pastry chef that ensures your applications are always available, resilient, and ready to delight the townsfolk without you having to worry about the nitty-gritty details. So, in the whimsical world of Kubernetes, Deployments are the enchanting spells that keep your digital bakeries running smoothly, even in the face of mythical mishaps!

Setup minikube on your local And Launching your Kubernetes Cluster with Deployment:

How to install minikube in AWS EC2 Ubuntu Machine:

Login to AWS Console:

  • Go to the AWS Management Console (https://aws.amazon.com/).

    Sign in with your AWS account.

  • Navigate to EC2:

    In the AWS Management Console, navigate to the EC2 service.

  • Launch an Instance:

    Click on the "Instances" in the left navigation pane.

    Click the "Launch Instances" button.

  • Choose an Amazon Machine Image (AMI):

    In the "Step 1: Choose an Amazon Machine Image (AMI)" section, select an Ubuntu AMI. You can search for "Ubuntu" in the search bar and choose an appropriate version (e.g., Ubuntu Server 20.04 LTS).

  • Choose an Instance Type:

    In the "Step 2: Choose an Instance Type" section, select "t2.xlarge" as the instance type.

    Click "Next: Configure Instance Details."

  • Configure Instance Details:

    In the "Step 3: Configure Instance Details" section:

    Set the "Number of instances" to 1.

    Optionally, you can configure additional settings, such as network, subnet, IAM role, etc.

    Click "Next: Add Storage."

  • Add Storage:

    In the "Step 4: Add Storage" section, you can leave the default storage settings or adjust as needed.

    Click "Next: Add Tags."

  • Add Tags:

    In the "Step 5: Add Tags" section, click "Add Tag."

    For "Key," enter "Name" and for "Value," enter "Jenkins" (or your preferred name).

    Click "Next: Configure Security Group."

  • Configure Security Group:

    In the "Step 6: Configure Security Group" section:

    Create a new security group or use an existing one.

    Add inbound rules to allow HTTP (port 80), HTTPS (port 443), and SSH (port 22) traffic.

    Click "Review and Launch."

  • Review and Launch:

    Review your configuration settings.

    Click "Launch."

  • Select Key Pair:

    In the key pair dialog, select "Choose an existing key pair" and choose the "minikube" key pair.

    Acknowledge that you have access to the private key.

    Click "Launch Instances."

  • View Instances:

    Once the instance is launched, you can view it in the EC2 dashboard.

    Wait for the instance to reach the "running" state.

Setup minikube in Ubuntu:

Go to Ubuntu Machine and update the ubuntu machine:

sudo apt-get update
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
minikube start
sudo apt-get install docker.io
sudo usermod -aG docker $USER && newgrp docker
sudo reboot
minikube start 
minikube start --driver=docker
sudo snap install kubectl --classic
kubectl get po -A

How to Setup minikube in Ubuntu Machine Live:

Launching your Kubernetes Cluster with Deployment:

First We check how many namespace, By default we have.

kubectl get namesapce

By default, We have 4 Name space that is default, kube-node-lease, kube-public, kube-system. Now we need to create new namespace that is "my-node-app".

kubectl crate namespce my-node-app

to check now how many namespace we have the command is.

kubectl get namespce

Now we have new name space that is "my-node-app" . After that we create one directory that is "Project".

and create development.yml file. Now What is Develpment in Kubernetes, "A Kubernetes Deployment YAML file is a configuration file written in YAML (YAML Ain’t Markup Language)that defines the desired state of a Kubernetes Deployment. This YAML file is used to create, update, or delete Deployments in a Kubernetes cluster. It contains a set of key-value pairs that specify various attributes and settings for the Deployment, such as the number of replicas, pod template specifications, labels, and more. "

Development Yaml File

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: my-node-app
  name: my-deployment-app
  labels:
    app: my-node-app
spec:
  replicas: 3
  selector:
    matchLabels:
        app: my-node-app
  template:
    metadata:
      namespace: my-node-app
      labels:
        app: my-node-app
    spec:
      containers:
      - name: my-deployemt-con
        image: ishusharmaece/my-note-app
        ports:
        - containerPort: 8000

After that we run this file, The command is.

kubectl apply -f develpoment.yml -n my-node-app

Now check Everything is ok or not, The command is.

 kubectl get deployment -n my-node-app

Now we have done 3/3, It is means Everything okk. Now for check 3 replicas is created or not, The command is.

kubectl get pods -n my-node-app

Now 3 Replicas is created so now we need to delete one replica but in deployment.ymal file say that if you need to delete one replica, After that is will create automatically again another replica. So let's do it.

Now we need to delete "my-deployment-app-5b6bfc9c5f-4w8wd", The command is.

 kubectl delete pod my-deployment-app-5b6bfc9c5f-4w8wd -n my-node-app

See the "my-deployment-app-5b6bfc9c5f-4w8wd" deleted but now check another replica is created or not automatically.

kubectl get pods -n my-node-app

See Automatically is created this replica "my-deployment-app-5b6bfc9c5f-dzg28", So this replica also called pods .