- Jenkins Server up and running.
- Docker and git installed inside Jenkins Server.
- Docker Hub account.
- AWS Account.
- GitHub Account.
- EKS Cluster running
- Basic Understanding of Jenkins, Docker and Kubernetes.
- For Jenkins Step By Step installation:- https://gist.github.com/sampathshivakumar/54449ea95540ad0fd0f0cf44beb54ff9
- Fork the below two Repositories.
- Python-Source-Code Repository: https://github.com/sampathshivakumar/Python-Source-Code.git
- K8s-Manifests Repository: https://github.com/sampathshivakumar/K8s-Manifests.git
- Repository names that you fork.
- Jenkins job names
- docker-hub repo name
- Don't change anything expect your username,passwords.
# In Python-Source-Code/Jenkinsfile
replace "dockersampath/packages" with "<your-dockerhub-username>/<repo-name>"
Note:- better don't change your repo name in docker hub.
# In K8s-Manifests/Jenkinsfile
replace bellow two line:-
sh "git config user.email sampathshivakumar@gmail.com" ---> sh "git config user.email <your-email-id>"
sh "git config user.name sampathshivakumar" ---> sh "git config user.name <git-user-name>"
sh "sed -i 's+dockersampath/packages.*+dockersampath/packages:${DOCKERTAG}+g' deployment.yaml"
sh "sed -i 's+<your-docker-hub-usename>/packages.*+<your-docker-hub-usename>/packages:${DOCKERTAG}+g' deployment.yaml"
# In K8s-Manifests/deployment.yaml
replace
- image: dockersampath/packages:5 ---> - image: <your-docker-hub-username>/packages:5
Don't worry we start from scratch.
Select Amazon Linux-2 AMI.
t2.micro
Enter the following command as root.
# To download Jenkins repo.
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
# To import key.
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
# Install java.
amazon-linux-extras install java-openjdk11 -y
# Check Version of Java.
java --version
#Install Jenkins.
yum install jenkins
# You can enable the Jenkins service to start at boot with the command.
systemctl enable jenkins
# You can start the Jenkins service with the command.
systemctl start jenkins
# You can check the status of the Jenkins service using the command.
systemctl status jenkins
**Browse to http://localhost:8080 and unlock jenkins by inputing password.
# Become root user
sudo su -
# Apply updates
yum update -y
# Install Docker
yum install docker -y
# Let’s check the version and info of the docker
docker info
# Enable Docker during boot time
systemctl enable docker.service
# Start Docker
systemctl start docker.service
# Check the status of Docker
systemctl status docker.service
Commands to control the docker service
sudo systemctl start docker.service --> To start the service
sudo systemctl stop docker.service --> To stop the service
sudo systemctl restart docker.service --> To restart the service
sudo systemctl status docker.service --> To get the service status
# Install git
yum install git -y
# Check the version of git
git --version
You have to run docker commands using jenkins user, while runing jenkins job.
# Add Jenkins user to Docker Group.
usermod -a -G docker jenkins
# Reload a Linux user's group assignments to docker
newgrp docker
# Check the user id. to see group we added
id jenkins
- Save GitHub credentials with ID "github"
- Save Docker Hub credentials with ID "dockerhub"
- Dont change "ID", "Repository" or any names as we are involving save name in jenkins-pipelines file.
Note:-For GitHub use Personal access tokens as password.
Note:-GitHub username means not your email. You can find it here on your GitHub page.
Job-1
Select Pipeline from scm and give Python-Source-Code-git repo url and change branch to main and click save.
Select This project is parameterized, give name "DOCKERTAG",Default Value as "latest"
Select Pipeline from scm and give K8s-Manifests-git-repo url and change branch to main and click save.
If you have configured everything correctly you should see all stages of pipeline executed successfully
Job-2 should also get trigged automatically
Congratulations you have done 90 % of Project as of now. Now we just need to setup EKS Cluster and install ArgoCD init.
Launch a new instance and install AWS CLI, eksctl, kubectl in to Create, and interact with EKS Cluster in AWS.
Select Amazon Linux-2 AMI.
t2.micro
AWS CLI Installation
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
# Check AWS CLI version
aws --version
Now Configure the AWS CLI with your AWS "Access key" and "Secret access key".
# trype aws configure and press enter, then follow the flow.
aws configure
Now Check by listing s3 buckets in your AWS account using AWS CLI.
Done, its showing my Bucket successfully, AWS CLI is configured correctly
Now lets install eksctl.
ARCH=amd64
PLATFORM=$(uname -s)_$ARCH
curl -sLO "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$PLATFORM.tar.gz"
tar -xzf eksctl_$PLATFORM.tar.gz -C /tmp && rm eksctl_$PLATFORM.tar.gz
sudo mv /tmp/eksctl /usr/local/bin
# Check the eksctl version.
eksctl version
Lets Install kubectl
curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.27.1/2023-04-19/bin/linux/amd64/kubectl
chmod +x ./kubectl
mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH
echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc
kubectl version --short --client
Command to Create EKS Cluster using eksctl command
eksctl create cluster --name <name-of-cluster> --nodegroup-name <nodegrpname> --node-type <instance-type> --nodes <no-of-nodes>
eksctl create cluster --name mycluster --nodegroup-name ng-test --node-type t3.medium --nodes 2
It will take 5-10 mins to create cluster.
We can see as of now there is no cluster in EKS
It's Done. Now lets see the cluster
Lets test some kubectl commands
# This will create a new namespace, argocd, where Argo CD services and application resources will live.
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd
rm argocd-linux-amd64
# By default, the Argo CD API server is not exposed with an external IP. To access the API server,
choose one of the following techniques to expose the Argo CD API server:
* Service Type Load Balancer
* Port Forwarding
# Change the argocd-server service type to LoadBalancer.
kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'
Get the load balancer url
kubectl get svc -n argocd
Enter the user name and Password
Login Using The CLI
argocd admin initial-password -n argocd
Enter Repository URL,set path to ./ , Cluster URL to https://kubernetes.default.svc, namespace to default and click save.
You should see the below, once your done
You can see the pods running in EKS Cluster
We can see the out of pods using load balancer url
kubectl get svc
ArgoCD will automatically syn for every 3 mins to manifest repo to pull and apply changes to EKS Cluster.
If your are intrested you can apply github web hook to automatically trigger jenkins job when developer commit changes in git repo. So that ArgoCD can pull those changes and apply in EKS Cluster.
eksctl delete cluster --name <name-of-cluster>
eksctl delete cluster --name mycluster
Thank you for reading this post! I hope you found it helpful. If you have any feedback or questions,Please connect with me on LinkedIn at https://www.linkedin.com/in/sampathsivakumar-boddeti-1666b810b/. Your feedback is valuable to me. Thank you!