Launching the Kubernetes pods and expose it with the help of Jenkins

Prerequisites

  • EC2 Instance: Begin by provisioning an EC2 instance with a T2-MEDIUM instance type.

  • Jenkins Installation: Install Jenkins on your EC2 instance.

  • Docker: Ensure Docker is installed and configured on your EC2 instance.

  • Kubernetes Setup: Setup Kubernetes on your EC2 instance.

Step 1: We will install kubectl.

COPY

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

give the file execution permission

COPY

sudo chmod +x kubectl

and then we will MV this file in default directory

COPY

sudo mv kubectl /usr/bin

Step 2: Install and setup jenkins and java.

Step 3: create a new job with freestyle which will execute the commands to launch and expose pods.

Step 4: Write these commands on execute shell of build step.

#launch ->> sudo kubectl create deployment myd1 --image=vimal13/apache-webserver-php

#Launch the port — > kubectl expose deployment myd1 --type=NodePort --port=80

After that click on build now your pods will be created and exposed.