How to Install Docker and Kubernetes in WSL2 (Ubuntu 20.04.6 LTS) without using Docker Desktop in Windows 10?

How to Install Docker and Kubernetes in WSL2 (Ubuntu 20.04.6 LTS) without using Docker Desktop in Windows 10?

Steps for wsl2 Ubuntu Installation of NodeJs, Docker, Kubernetes, Minikube, Ingress Nginx and fix related issues.

·

4 min read

  1. For wsl2 Ubuntu Installation, In Windows Search, type Turn Windows features on or off tick checkbox for windows subsytem for linux click ok and then restart laptop

  2. To Install Ubuntu20.04 or any other linux os we have two ways

    a.) Using Poweshell as admin

    (i)Type command wsl --install (By default Ubuntu will be installed) then set your username and password

    To Dispaly avaialble linux distros and then Install

    (ii) wsl --list --online

    b.) Using Microsoft Store search Ubuntu20.04 or any distro and click on get then set your username and password

  3. After Installation commands

    i.) sudo apt update

  4. How to Fix “temporary failure resolving archive.ubuntu.com” Error If you get this error while sudo apt update or any other Installation then type

    i.) sudo nano /etc/resolv.conf (this will open resolv.conf) now

    ii.) nameserver 8.8.8.8 (press ctrl + x and then shift Y then enter)

  5. Steps To install nodejs lts

    i.) search nodejs on chrome open https://nodejs.org click on other downloads

    ii.) scroll down and click Installing Nodejs via package manager

    iii.) Click on Debian and Ubuntu based Linux distributions.

    iv.) Click Node.js binary distributions scroll down and copy the below command for node v.18 curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - && \
    sudo apt-get install -y nodejs

  6. Editing the file to add systemd to WSL 2

    i.) sudo nano /etc/wsl.conf (this will open file then add)

    ii.) [boot] systemd=true (press ctrl + x and then shift + y and then enter)

  7. Steps to Install docker in wsl2 Ubuntu20.04

    a.) Older versions of Docker were called docker, docker.io, or docker-engine. If these are installed, uninstall them: sudo apt-get remove docker docker-engine docker.io containerd runc

    b.) Update the apt package index

    sudo apt-get update

    c.) install packages to allow apt to use a repository over HTTPS:

    sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

    d.) sudo mkdir -p /etc/apt/keyrings

    e.) Add Docker’s official GPG key:

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

    f.) Use the following command to set up the stable repository: 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

    g.) sudo apt update

    h.) sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin

    i.) To start docker and check status and run container

    i.) sudo service docker start ii. sudo service docker status iii. sudo docker run hello-world

    j.) To add user to docker group sudo usermod -aG docker $User && newgrp docker

    k.) sudo apt install -y conntrack

  8. To Install Kubernetes in wsl2

    i.) sudo snap install microk8s --classic

    ii.) sudo microk8s status

    iii.) sudo microk8s kubectl get nodes

  9. If you get error cannot connect to snapstore then

    i.) sudo apt update sudo apt install snapd sudo snap install snap-store

    If you still get error then Try the commands below and ping api.snapcraft.io (again) if not then

    i.) sudo snap unset system proxy.http

    ii.) sudo snap unset system proxy.https

    iii.) sudo systemctl restart snapd

  10. To install minikube

    i.) curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

    ii.) chmod +x ./minikube

    iii.) sudo mv ./minikube /usr/local/bin/

    iv.) minikube config set driver docker

  11. To Install kubectl

    i.) curl -LO "[dl.k8s.io/release/$(curl](https://dl.k8s.io.. -L -S https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl/bin/linux/amd64/kubectl)"

    ii.) curl -LO "[dl.k8s.io/$(curl](https://dl.k8s.io/$(curl) -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256/bin/linux/amd64/kubectl.sha256)"

    iii.) echo "$(cat kubectl.sha256) kubectl" | sha256sum --check iv. chmod +x kubectl mkdir -p ~/.local/bin mv ./kubectl ~/.local/bin/kubectl v. sudo chown $USER:$USER /usr/bin/kubectl (you can replace $user with your user)

  12. minikube start

  13. minikube addons list then minikube start

  14. kubectl get nodes

  15. To Install Ingress Nginx

    i.) minikube addons enable ingress (prefer this than the below then) or

    ii.) microk8s enable ingress

  16. If you get client side throttling then increase memory

    i.) minikube stop

    ii.) minikube config set memory 5972 (config file is located at ~/. minikube/config/config. json)

  17. If you get sshd: no hostkeys available --exiting then

    i.) sudo service ssh status

    ii.) sudo ssh-keygen -A

    iii.) sudo service ssh start

    iv.) ifconfig | grep inet v. ssh @<first ip address from above ex 172.25.134.63>

If you want to take advantage of wsl2 for your development environment and don't want to use docker desktop in windows10 then above steps can help you install docker and tackle errors while installations. Till next time, happy coding!