Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Module 11 - Kubernetes on AWS - EKS

This repository contains a demo project created as part of my DevOps studies in the TechWorld with Nana – DevOps Bootcamp.

Demo Project: CD - Deploy to EKS cluster from Jenkins Pipeline

Technologies used: Kubernetes, Jenkins, AWS EKS, Docker, Linux

Project Description:

  • Install kubectl and aws-iam-authenticator on a Jenkins server
  • Create kubeconfig file to connect to EKS cluster and add it on Jenkins server
  • Add AWS credentials on Jenkins for AWS account authentication
  • Extend and adjust Jenkinsfile of the previous CI/CD pipeline to configure connection to EKS cluster

Prerequisites

Before starting, complete the following setup modules:


Step 1 — Install kubectl and aws-iam-authenticator on the Jenkins server

Note: aws-iam-authenticator is bundled with eksctl and installed automatically when you use it.

1.1 Install kubectl

Enter the Jenkins container as root:

docker ps
docker exec -it -u 0 <container_id> bash

Download and install kubectl:

curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
mv ./kubectl /usr/local/bin/kubectl

# Verify installation
kubectl version --client

1.2 Install aws-iam-authenticator

Still inside the Jenkins container, run:

curl -Lo aws-iam-authenticator \
  https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v0.6.11/aws-iam-authenticator_0.6.11_linux_amd64
chmod +x ./aws-iam-authenticator
mv ./aws-iam-authenticator /usr/local/bin

# Verify installation
aws-iam-authenticator version

Step 2 — Create and deploy kubeconfig to the Jenkins server

2.1 Create the EKS cluster (if it doesn't exist)

See the cluster config: cluster.yaml Reference: eks-module-11.3

eksctl create cluster -f cluster.yaml

2.2 Build the kubeconfig file

Copy the template: config-template.yaml

cp ./config-template.yaml config.yaml

Replace <cluster-name> with demo-cluster, then fill in the cluster endpoint and certificate. Choose one option:

Option A — AWS Console

Navigate to EKSClustersdemo-clusterOverview, then copy:

  • API server endpointcluster.server
  • Certificate authoritycluster.certificate-authority-data

EKS API server endpoint

Option B — Local kubeconfig

Pull the values from your local ~/.kube/config:

  • cluster.server
  • cluster.certificate-authority-data

2.3 Deploy kubeconfig to the Jenkins server

Transfer the file to your DigitalOcean droplet:

scp config.yaml root@<DROPLET_IP>:/root

Create the .kube directory inside the Jenkins container:

docker ps
docker exec -it <container_id> bash -c "mkdir -p ~/.kube && exit"

Copy the config into the container:

docker cp config.yaml <container_id>:/var/jenkins_home/.kube/config

# Verify the file was copied
docker exec -it <container_id> cat ~/.kube/config

Step 3 — Configure a Multibranch Pipeline in Jenkins

  1. Go to DashboardNew Item
  2. Name it java-maven-app, select Multibranch Pipeline, click OK

Branch Sources:

Click Add sourceGitHub and fill in:

Field Value
Credentials github
Repository HTTPS URL https://github.com/explicit-logic/eks-module-11.4

Click Validate to confirm access.

Behaviors — click Add and enable:

  • Discover branches

Build Configuration:

  • Script Path: Jenkinsfile
  1. Click Save — Jenkins will scan the repository and create a job for each branch.

Step 4 — Add AWS credentials to Jenkins

4.1 Create an IAM user for Jenkins

  1. Go to IAMUsersCreate user
    • Name: jenkins
  2. Select Attach policies directly and attach the following managed policies:
    • AmazonEKSClusterPolicy
    • AmazonEKSWorkerNodePolicy
    • AmazonEC2ContainerRegistryFullAccess
  3. Complete user creation.

AWS Jenkins IAM user

4.2 Grant the IAM user access to the EKS cluster

Find the user's ARN in the IAM console:

Jenkins user ARN

eksctl create iamidentitymapping \
  --cluster demo-cluster \
  --region <REGION> \
  --arn arn:aws:iam::<ACCOUNT_ID>:user/jenkins \
  --group system:masters \
  --username jenkins

4.3 Create an access key

  1. In IAM, open the jenkins user → Security credentialsCreate access key
  2. Use case: Application running outside AWS
  3. Copy the Access key and Secret access key

Access key

4.4 Store credentials in Jenkins

Go to java-maven-appCredentialsGlobalAdd Credentials

Add two Secret text credentials:

ID Secret
AWS_ACCESS_KEY_ID <Access key>
AWS_SECRET_ACCESS_KEY <Secret access key>

Jenkins AWS credentials


Step 5 — Update Jenkinsfile to deploy to EKS

Add a deploy stage to your Jenkinsfile:

stage('deploy') {
    environment {
        AWS_ACCESS_KEY_ID     = credentials('AWS_ACCESS_KEY_ID')
        AWS_SECRET_ACCESS_KEY = credentials('AWS_SECRET_ACCESS_KEY')
    }
    steps {
        script {
            echo 'Deploying Docker image to EKS...'
            sh 'kubectl create deployment nginx-deployment --image=nginx'
        }
    }
}

Demo

Demo

About

CD - Deploy to EKS cluster from Jenkins Pipeline

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors