Sunday, 19 June 2022

How Automate Kubernetes/docker with jenkins (Installation)

 Step 1: Install Jenkins on Ubuntu 18.04 instance

apt updateapt install openjdk-11-jre-headless -yjava -version


curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null

echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null


Once the Jenkins repository is enabled, update the apt package list and install the latest version of Jenkins by typing:

sudo apt-get updatesudo apt-get install jenkins

systemctl status jenkins

See link for complete configuration guide of jenkins : https://www.devopstreams.com/2020/08/pleasefollow-steps-to-install-java.html


Step 2: Add Jenkins User to Sudoers List


Now configured Jenkins user as administrator to do all operation and connect eks cluster.

$ vi /etc/sudoers

Add at end of file

jenkins ALL=(ALL) NOPASSWD: ALL

Save and exit

:wq!


Now we can use Jenkins as a sudo user


sudo su - jenkins


Step 3:

Docker installation

sudo apt install docker.io -y

Once done you can check the version also.

docker --version

Now add Jenkins user in the docker group

sudo usermod -aG docker jenkins

Now we are installing aws CLI, kubectl, and eksctl command-line utility on the Jenkins server.

Follow the below commands,

Step 4:

sudo apt  install awscli


To configure the AWS the first command we are going to run is

aws configure

Then enter your Access/Secret key, Format: json and region:us-east-2


Step 5:

Install eksctl

 curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp

sudo mv /tmp/eksctl /usr/local/bin

  eksctl version

If you get something like "no command found" enter the below command

cp /usr/local/bin/eksctl /usr/bin -rf

Step 6:

Install kubectl

 curl -o kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/kubectl

 chmod +x ./kubectl

mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH

sudo mv ./kubectl /usr/local/bin

 kubectl version --short --client


Step 7:

Install aws-iam-authenticator

   curl -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/aws-iam-authenticator

    chmod +x ./aws-iam-authenticator

   mkdir -p $HOME/bin && cp ./aws-iam-authenticator $HOME/bin/aws-iam-authenticator && export PATH=$PATH:$HOME/bin

   echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc

sudo mv ./aws-iam-authenticator /usr/local/bin

   aws-iam-authenticator help


Step 8: Make sure you Create a role with Administrator Access and attach your role to the instance

 Step 9: Create your jenkins job --->Build Enviroment---->Execute Shell---->enter your kubernetes commands

Or

Create Pipeline and run your commands in stages

Thanks you








No comments:

Post a Comment

How to upgrade Maven

  java.lang.IllegalStateException I had installed maven in my ubuntu using command  apt install maven This installed maven in path /usr/shar...