How to install docker, aws cli, eksctl, kubectl for Jenkins in Linux Ubuntu 18.04?
Keywords
- Docker
- Aws cli
- kubectl
- Jenkins
- shell
- Package Manager
- linux file system tree
- linux shell
- linux environment
- linux access control and permissions
- linux package management
Relevant preparation for the tutorial
- Linux system understanding and solid foundations:
- Understand the file system tree (Chapter 2 Navigation)
- Understand the shell (Chapter 1 What is the shell?)
- Understand linux access control and permissions (Chapter 9 Permissions)
- Understand the “environment” in linux (Chapter 11 The environment)
- Understand package management in linux (Chapter 14 Package management)
Book: The linux command line
https://www.amazon.com/Linux-Command-Line-2nd-Introduction-ebook/dp/B07J43H42Z
1. Create the aws EC2 instance where jenkins is going to run
- Create the aws EC2 instance where jenkins is going to run. Create the EC2 instance Ubuntu Server 18.04 LTS
2. Add security rule for ssh
3. Add security rule for custom tpc in port 8080
To connect with SSH
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html
2. Installing Jenkins for Ubuntu 18.04
Software Prerequisites
- Java. Please!!!! install Java ⚠️⚠️. The following versions are supported:
Java 8 runtime environments, both 32-bit and 64-bit versions are supported (RECOMMENDED ❗️❗️❗️)
Since Jenkins 2.164 and 2.164.1 [1], Java 11 runtime environments are supported
Instructions
- Install Java. For that we are going to use the Ubuntu Package Manager called APT. For that we run the following commands in the command shell:
Update the repositories
sudo apt update
Install java 8
sudo apt install openjdk-8-jdk
Test that it was correctly done:
java -version
The result looks like:
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1ubuntu1-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
Installation scope: Global and accessible to all users
Package location: /usr/bin/java
2. Install jenkins. Run these commands in the command shell:
2.2 Get the package key
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > \
/etc/apt/sources.list.d/jenkins.list'
The exact commands you can copy from here https://www.jenkins.io/doc/book/installing/#debianubuntu
2.3 Install jenkins
sudo apt-get update
sudo apt-get install jenkins
The exact commands you can copy from here https://www.jenkins.io/doc/book/installing/#debianubuntu
Test that it was correctly done:
sudo systemctl status jenkins
The result looks like:
Installation scope: Global and accessible to all users
Package location:
References
Jenkins official Ubuntu installation guide
Configure Jenkins
- Go to the Jenkins UI http://your_server_ip_or_domain:8080.
- Get the passwords by running:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
3. Use the password and continue the set up
4. Follow this to install blueocean: https://www.jenkins.io/doc/book/blueocean/getting-started/#on-an-existing-jenkins-instance
5. Restart jenkins
sudo systemctl restart jenkins
3. Installing aws cli
- Install unzip (only if it is not installed)
sudo apt install unzip
2. Install glibc (only if it is not installed)
sudo apt install glibc-source
3. Install aws cli version 2. Please follow the steps in this guide to install it:
Installation scope: Global and accessible to all users
Package location: By default, the files are all installed to /usr/local/aws-cli
, and a symbolic link is created in /usr/local/bin
Test that it was correctly done:
- Confirm installation by running:
aws --version
Expected output:
aws-cli/2.0.23 Python/3.7.4 Linux/4.14.133-113.105.amzn2.x86_64 botocore/2.0.0
- Confirm that it was installed in a global location, otherwise it is not going to be accessible by jenkins
which aws
Expected output:
/usr/local/bin/aws
4. Configure the aws cli
- Set the aws credentials in the ubuntu user. Run:
aws configure
⚠️ This credentials are only available to the ubuntu user and not by jenkins, that is why we need to use the next aws plugin and set credentials for jenkins.
Credentials location: ~/.aws (Home directory)
Home directory in this case: /home/ubuntu/.aws
2. Install the aws plugin
3. Restart jenkins
sudo systemctl restart jenkins
4. Create the credentials in jenkins:
5. Installing eksctl
- Please follow the instructions in the section “Install eksctl” in this link: https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html#eksctl-kubectl
Test that it was correctly done:
- Confirm installation by running:
eksctl version
- Confirm that it was installed in a global location, otherwise it is not going to be accessible by jenkins
which eksctl
Expected output:
/usr/local/bin/eksctl
2. Create the kubernetes cluster using your ubuntu user in the ec2 instance. For this to work you need to have configured aws credentials for the ubuntu user!!
6. Installing kubectl
- Please follow the instructions in this link https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html#eksctl-kubectl
❗️❗️For step 4 please make sure to follow this so that is installed in /usr/local/bin
Test that it was correctly done:
- Confirm installation by running:
kubectl version
- Confirm that it was installed in a global location, otherwise it is not going to be accessible by jenkins
which kubectl
Expected output:
/usr/local/bin/kubectl
2. Create the configutation file in for the jenkins user in its home directory automatically in the Jenkinsfile
Configutation location: ~/.kube (Home directory)
Home directory in this case: /home/jenkins/.kube
You need to run the following command in your jenkinsfile to create the configutation file (kubeconfig)
⚠️ These configutations are only available to the ubuntu user and not by jenkins, that is why we need to create a configutations file in the Jenkinsfile to make it available to the jenkins user.
7. Installing docker
- You can use this tutorial for linux ubuntu https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-18-04
- Create in Jenkins the credentials for Docker
3. If you need to add a user to the docker
group that you’re not logged in as, declare that username explicitly using:
sudo usermod -aG docker jenkins
4. Restart jenkins so that the changes are put in place
sudo systemctl restart jenkins