Docker and Kubernetes are the heroes of the DevOps world.
Docker is a containerization platform and Kubernetes is a container orchestrator for platforms like Docker.
This article will discuss how we can set up Docker and Kubernetes on our Ubuntu machine.
Setting Up Docker
We will be setting up Docker by adding its repository to our package index and then installing the Docker Debian packages via our apt
package manager.
Let's begin.
Step-1: Refreshing package index and installing packages to use repository over https
First, we will refresh our package index, and install some packages which will help us add PGP keys and setting up therepository right through https
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
Step-2: Adding Docker's official GPG key
Run the below command, and it will automatically add Docker PGP keys to our system
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Step-3: Adding docker repository to apt
package index
Now that we are done adding keys, it's time to add the repository URL which will help us install and timely update Docker on our system.
$ echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Step-4: Refreshing package index and Installing Docker apt
packages
Now finally, it's time to install Docker. But first, we will need to refresh our package index as well.
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Step-5: Testing Docker
Now that we have installed Docker, let us test it and give it a try.
sudo docker run hello-world
After you have run the above command if everything works fine you see output like below the image on your screen.
Setting Up Kubernetes
We will go through the process to install Kubernetes through the apt
package manager and snap
both. You can choose which suits you better
Installing via apt
package manager
Step-1: Refreshing package index and installing packages to use repository over https
First, we will refresh our package index, and install some packages which will help us add PGP keys and setting up the repository right through https
$ sudo apt-get update
$ sudo apt-get install -y apt-transport-https ca-certificates curl
Step-2: Adding Kubernetes PGP key
Run the below command, and it will automatically add Kubernetes PGP keys to our system
$ sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
Step-3: Adding Kubernetes repository to package index
Now that we are done adding keys, it's time to add repository URL which will help us install and timely update Kubernetes (kubectl
) on our system.
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
Step-4: Refreshing package index and installing Kubectl
Now finally, its time to install Kubernetes(kubectl
). But first, we will need to refresh our package index as well.
$ sudo apt-get update
$ sudo apt-get install -y kubectl
Installing Kubectl via snap
package manager
Installing kubectl
via snap
is pretty easy and a single command work. You can also pick this alternative to set up Kubernetes. Though I will recommend installing via apt
package manager as it is easily updatable.
$ snap install kubectl --classic
Top comments (0)