Deploying Reddit Copy on Kubernetes Cluster using Ingress.

Deploying Reddit Copy on Kubernetes Cluster using Ingress.

Prerequisites:

?????????? EC2 (AMI- Ubuntu, Type- t2.medium)

?????????? Docker

?????????? Minikube

?????????? Kubectl

?

Follow below steps for install all necessary prerequisite:

#Docker Installation steps

sudo apt-get update

sudo apt-get install docker.io -y

sudo usermod -aG docker $USER && newgrp docker        

# For Minikube & Kubectl

sudo install minikube-linux-amd64 /usr/local/bin/minikube

sudo snap install kubectl –classic

minikube start --driver=docker        

?

Clone the source code:

git clone https://github.com/LondheShubham153/reddit-clone-k8s-ingress.git        

Building Docker Image:

You can build docker image using below commands:

docker build -t <DockerHub_Username>/<Imagename> .        

?

docker build -t trainwithshubham/reddit-clone .

or

docker build -t ashraw10/reddit-clone .        

Push the image to Docker hub

First you have to login on Docker hub using below command

docker login ?

give username and password.        

Write a Kubernetes Manifest File

When you are going to deploy to Kubernetes or create Kubernetes resources like a pod, replica-set, config map, secret, deployment, etc., you need to write a file called manifest that describes that object and its attributes either in yaml or json.

?

Let’s create a Deployment file for our Application

Using the following code for the Deployement.yml file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: reddit-clone-deployment
  labels:
    app: reddit-clone
spec:
  replicas: 2
  selector:
    matchLabels:
      app: reddit-clone
  template:
    metadata:
      labels:
        app: reddit-clone
    spec:
      containers:
      - name: reddit-clone
        image: trainwithshubham/reddit-clone
        ports:
        - containerPort: 3000
        

Write Service.yml file

apiVersion: v1
kind: Service
metadata:
  name: reddit-clone-service
  labels:
    app: reddit-clone
spec:
  type: NodePort
  ports:
  - port: 3000
    targetPort: 3000
    nodePort: 31000
  selector:
    app: reddit-clone
        

Deploy the app to Kubernetes & Create a Service for It

Now, we have a deployment file for our app and we have a running Kubernetes cluster. We can deploy the app to Kubernetes.

Run following command:

kubectl apply -f deployment.yml

kubectl apply -f service.yml        

?Check your deployment and services using below command:

kubectl get deployment -o wide

kubectl get services -o wide        

Let's Configure Ingress

Ingress in Kubernetes:

Pods and services in Kubernetes have their own IP; however, it is normally not the interface you'd provide to the external internet. Though there is a service with node IP configured, the port in the node IP can't be duplicated among the services. It is cumbersome to decide which port to manage with which service. Furthermore, the node comes and goes, it wouldn't be clever to provide a static node IP to an external service. Ingress defines a set of rules that allows the inbound connection to access Kubernetes cluster services. It brings the traffic into the cluster at L7 and allocates and forwards a port on each VM to the service port.

Write ingress.yml file using below code:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-reddit-app
spec:
  rules:
  - host: "domain.com"
    http:
      paths:
      - pathType: Prefix
        path: "/test"
        backend:
          service:
            name: reddit-clone-service
            port:
              number: 3000
  - host: "*.domain.com"
    http:
      paths:
      - pathType: Prefix
        path: "/test"
        backend:
          service:
            name: reddit-clone-service
            port:
              number: 3000
        

Apply the ingress.yml using below commands:

Kubectl apply –f ingress.yml        

Use below command to verify ingress is running correctly:

kubectl get ingress ingress-reddit-app        

To check ingress status used below command:

Kubectl get ingress –o wide        

Test Ingress:

Now It's time to test your ingress so use the?curl -L domain/test?command in the terminal.

Note: open the 3000 port in a security group of your Ec2 Instance

Used Ec2_ip to see the deployed application on browser using

EC2_ip:3000


You have successfully deployed the Reddit clone app using ingress on Kubeadm cluster.

Thank you all!


Gagandeep Chhabra

Technical Product Owner | SDLC | Platform Engineering | FinOps | Technical Architect | Django Rest Framework | Microservices | Product development | RnD

1 年

Good work

回复
HARSHIT SINGH

Machine Learning & Data Science Professional | Driving Insights & Automation Excellence | TCS Solution Architect | Process Optimization & Innovation Expert | Corporate Trainer & Mentor

1 年

Keep growing keep learning

回复
Nimish Mulkalwar

Looking for Job Change | DevOps Engineer at Yash Technologies Pvt Ltd | AWS | AZURE x2 | Jenkins | Docker | Terraform | Linux | Kubernetes | Github

1 年

Congrats Aashish R.

回复
Rashmi Bhosale

DevSecOps Consultant at KPMG | AWS Certified Solution Architect | Ex - TCS

1 年

Great Work Aashish R.

回复
Akash Jadhav

Microsoft Certified Data Analyst | Power BI | DAX | SQL | Python | Linux | TCS Digital

1 年

Congratulations on the first article Aashish

回复

要查看或添加评论,请登录

Aashish R.的更多文章

  • Serverless on AWS

    Serverless on AWS

    Are you excited to know about serverless architecture!! You can build and run applications without thinking about…

  • TerraWeek Day 7 - Advanced Terraform Topics

    TerraWeek Day 7 - Advanced Terraform Topics

    Welcome to the advanced TerraWeek challenge! In this phase, we will dive into advanced topics that will enhance your…

  • TerraWeek Day 6: Terraform Providers

    TerraWeek Day 6: Terraform Providers

    Introduction In this blog, we will explore the concept of Terraform providers, compare major cloud providers such as…

    2 条评论
  • TerraWeek Day 5

    TerraWeek Day 5

    Task 1: What are modules in Terraform and why do we need modules in Terraform? You already write modules Even when you…

  • Terraweek Day 4 Knowledge about Terraform state, Local and Remote configurations

    Terraweek Day 4 Knowledge about Terraform state, Local and Remote configurations

    Task 1:The importance of Terraform state in managing infrastructure The primary purpose of Terraform state is to store…

  • TerraWeek Day 3

    TerraWeek Day 3

    Task 1:Create a Terraform configuration file to define a resource of AWS EC2 instance, Azure storage account, Google…

    1 条评论
  • HashiCorp Configuration language(HCL)

    HashiCorp Configuration language(HCL)

    #TerraWeekChallenge DAY 2 Terraform Syntax , Block parameter and arguments ,variable , data types , expressions , .tf…

  • Deployment of a Microservices Application on K8s- Do MongoDB App Deployment

    Deployment of a Microservices Application on K8s- Do MongoDB App Deployment

    Kubernetes, also known as K8s, is an open-source system for automating deployment, scaling, and management of…

  • How to Install terraform on Ubuntu server.

    How to Install terraform on Ubuntu server.

    What is Terraform? HashiCorp Terraform is an infrastructure as code tool that lets you define both cloud and on-prem…

    1 条评论

社区洞察

其他会员也浏览了