Part 3



In Part 2 of this 5-part blog, we installed the Ubuntu operating system on the system and took an AMI of the set up. 

In this section, we will install the docker and all the other OS components and tools required for Kubernetes cluster. 

IMPORTANT: We will now have to use a different type of EC2 instance for the docker and Kubernetes installation and configuration, as these require more vCPU and RAM. 


The minimum requirements for docker and Kubernetes are 2 vCPU & 2 GB RAM. 


We will use the previously created AMI “ubuntu-base-image” and launch an instance using “t3a.small”. You can use any other instance type with more vCPU or RAM, however, to keep costs to a minimum, we will use a “t3a.small” instance type for the initial configuration. 






Important: After creating a new instance with instance type “t3a.small”, login as the “jenkins” user.

For the Kubernetes cluster to work, SWAP must be disabled at the operating system level. 

Disable the swap memory. To perform this action, execute swapoff:

    • $ sudo swapoff -a

In case there is an entry for “swap” in /etc/fstab file, then type use the below sed command:

    • $ sudo sed -i ‘/ swap / s/^\(.*\)$/#\1/g’ /etc/fstab

Run the following command to update system packages and repository index to the latest versions.

    • $ sudo apt update

Once the system packages are updated, run the below command to install AWS CLI.

    • $ sudo apt install awscli -y

Run the following command to configure “awscli” to communicate with your AWS account and services.

    • $ aws configure 


Enter the below details accordingly:

    • AWS Access Key ID [IAM user’s Access key]
    • AWS Secret Access Key [IAM user’s secret key]
    • Default region name [Aws region]
    • Default output format [JSON format is fine]


Install the below linux utilities in your ubuntu base-os

    • $ sudo apt install unzip -y 

    • $ sudo apt install net-tools -y

    • $ sudo apt-get install jq -y



Install AWS SSM. This is useful if this base image will be used in a multi-master Kubernetes cluster. 

    • $ sudo snap install amazon-ssm-agent –classic

    • $ sudo systemctl enable

    • $ sudo systemctl start






Install docker on the EC2 instance. Docker has to be installed on Master and Worker nodes, hence we are installing it on the base image, which will be used for both master and worker nodes. 


Login as user “jenkins

    • $ sudo apt-get update

    • $ sudo apt-get install \ca-certificates \curl \gnupg \lsb-release


Add Docker’s official GPG key:

    • $ sudo mkdir -m 0755 -p /etc/apt/keyrings

    • $ curl -fsSL | sudo gpg –dearmor -o /etc/apt/keyrings/docker.gpg


Use the following command to set up the repository:

    • $ echo \”deb [arch=$(dpkg –print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \$(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null


Update the apt package index:

    • $ sudo apt-get update


To install the latest version of docker, run:

    • $ sudo apt-get install docker-ce docker-ce-cli docker-buildx-plugin docker-compose-plugin

Press ‘Y’ when prompted

To check if docker is installed correctly

    • $ sudo docker version

This will give the docker version installed.


Add your user to the docker group.

    • $ sudo usermod -aG docker jenkins 

    • $ docker version

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.24/version: dial unix /var/run/docker.sock: connect: permission denied


If you get this error, log out from the current session and log in again as the jenkins user. Even though user “jenkins” is added to the “docker” group, it requires exiting the current session and logging in again.


Configure Docker to start on boot with systems

    • $ sudo systemctl enable docker.service

    • $ sudo systemctl enable containerd.service

    • $ docker version

This should now give you the installed docker versions. 



This completes the docker installation on the Ubuntu base operating system.


If you want to take an AMI of the ubuntu system, you can do so now, before installing the Kubernetes components. This ubuntu image with docker components can be reused for any docker operations. 


Part 2 –> Installing the Ubuntu OS


Part 4 –> Kubernetes installation and configuration.