Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brucebentley/fbce61ad5b6f0e4de53c7d632dbb8d03 to your computer and use it in GitHub Desktop.
Save brucebentley/fbce61ad5b6f0e4de53c7d632dbb8d03 to your computer and use it in GitHub Desktop.

Revisions

  1. brucebentley revised this gist Dec 5, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@

    Nowadays software is build mostly targeting Linux. Life is great as a Mac OS user since we can pretty much install everything through `brew`. Unfortunately thing start going pear shape when we have Windows 10 machines as part of the team and the shared tooling just stops working.

    The following post describes how to set up a Windows 10 desktop as a good Kube ready citizen in the Team.
    The following post describes how to setup your Windows 10 & WSL development environment(s) so that you're able to use all the various Kubernetes tooling.

    ## STEP 1:

  2. brucebentley revised this gist Dec 5, 2021. No changes.
  3. brucebentley revised this gist Dec 5, 2021. 4 changed files with 12 additions and 11 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ## Connecting Docker cli and Kubectl to Docker Desktop for Windows
    ## Connecting Docker CLI & Kubectl To Docker Desktop For Windows

    ### Install Kubectl, Docker, Helm, etc
    ### Install Kubectl, Docker, Helm, etc.

    > View details here: https://gist.github.com/xynova/87beae35688476efb2ee290d3926f5bb
    4 changes: 2 additions & 2 deletions Enable WSL and Ubuntu 16.04 on Windows 10.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ## Enable WSL and Ubuntu 16.04 on Windows 10
    ## Enable WSL & Ubuntu 20.04 On Windows 10

    **References:**
    - https://docs.microsoft.com/en-us/windows/wsl/install-win10
    @@ -15,7 +15,7 @@ Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-L
    ```


    Download Ubutnu 16.04 (16.04 has been patched for over a year):
    Download Ubutnu 20.04 (20.04 has been patched for over a year):

    ```Powershell
    Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile Ubuntu.appx -UseBasicParsing
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ## Installing Kubernetes and Docker tools on Windows 10 Ubuntu WSL
    ## Installing Kubernetes & Docker Tools On Windows 10 Ubuntu WSL

    ### Enter a WSL ubuntu session

    13 changes: 7 additions & 6 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,28 @@
    # Setting up the Kubernetes tooling on Windows 10 WSL
    # Setting Up The Kubernetes Tooling On Windows 10 WSL

    !["Thanks to Panos Sakalakis @meymigrou for making this photo available freely on Unsplash 🎁"](https://images.unsplash.com/photo-1516572783790-114414e34ba4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1000&q=80)
    ![](https://images.unsplash.com/photo-1516572783790-114414e34ba4?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&dl=panos-sakalakis-AwDVMJKMjlU-unsplash.jpg)

    Nowadays software is build mostly targeting Linux. Life is great as a Mac OS user since we can pretty much install everything through `brew`. Unfortunately thing start going pear shape when we have Windows 10 machines as part of the team and the shared tooling just stops working.

    Nowadays software is build mostly targeting Linux. Life is great as a Mac OS user since we can pretty much install everything through ‘brew’. Unfortunately thing start going pear shape when we have Windows 10 machines as part of the team and the shared tooling just stops working.
    The following post describes how to set up a Windows 10 desktop as a good Kube ready citizen in the Team.

    ## STEP 1:

    _Set up an Ubuntu WSL machine as described below:_

    [](https://gist.github.com/brucebentley/fbce61ad5b6f0e4de53c7d632dbb8d03#file-enable-wsl-and-ubuntu-16-04-on-windows-10-md)
    [Enable WSL and Ubuntu 16.04 on Windows 10](https://gist.github.com/brucebentley/fbce61ad5b6f0e4de53c7d632dbb8d03#file-enable-wsl-and-ubuntu-16-04-on-windows-10-md)

    ## STEP 2:

    _Install the Kube and Docker tools on Ubuntu WSL:_

    [](https://gist.github.com/brucebentley/fbce61ad5b6f0e4de53c7d632dbb8d03#file-installing-kubernetes-and-docker-tools-on-windows-10-ubuntu-wsl-md)
    [Installing Kubernetes and Docker tools on Windows 10 Ubuntu WSL](https://gist.github.com/brucebentley/fbce61ad5b6f0e4de53c7d632dbb8d03#file-installing-kubernetes-and-docker-tools-on-windows-10-ubuntu-wsl-md)

    ## STEP 3:

    _Connect Kubectl and Docker to the Windows side of things:_

    [](https://gist.github.com/brucebentley/fbce61ad5b6f0e4de53c7d632dbb8d03#file-connecting-docker-cli-and-kubectl-to-docker-desktop-for-windows-md)
    [Connecting Docker cli and Kubectl to Docker Desktop for Windows](https://gist.github.com/brucebentley/fbce61ad5b6f0e4de53c7d632dbb8d03#file-connecting-docker-cli-and-kubectl-to-docker-desktop-for-windows-md)

    ## STEP 4:

  4. brucebentley revised this gist Dec 5, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ _Set up an Ubuntu WSL machine as described below:_

    _Install the Kube and Docker tools on Ubuntu WSL:_

    []()
    [](https://gist.github.com/brucebentley/fbce61ad5b6f0e4de53c7d632dbb8d03#file-installing-kubernetes-and-docker-tools-on-windows-10-ubuntu-wsl-md)

    ## STEP 3:

  5. brucebentley revised this gist Dec 5, 2021. No changes.
  6. brucebentley revised this gist Dec 5, 2021. No changes.
  7. brucebentley revised this gist Dec 5, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ The following post describes how to set up a Windows 10 desktop as a good Kube r

    _Set up an Ubuntu WSL machine as described below:_

    []()
    [](https://gist.github.com/brucebentley/fbce61ad5b6f0e4de53c7d632dbb8d03#file-enable-wsl-and-ubuntu-16-04-on-windows-10-md)

    ## STEP 2:

  8. brucebentley revised this gist Dec 5, 2021. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -9,15 +9,20 @@ The following post describes how to set up a Windows 10 desktop as a good Kube r

    _Set up an Ubuntu WSL machine as described below:_

    []()

    ## STEP 2:

    _Install the Kube and Docker tools on Ubuntu WSL:_

    []()

    ## STEP 3:

    _Connect Kubectl and Docker to the Windows side of things:_

    [](https://gist.github.com/brucebentley/fbce61ad5b6f0e4de53c7d632dbb8d03#file-connecting-docker-cli-and-kubectl-to-docker-desktop-for-windows-md)

    ## STEP 4:

    _Celebrate!_ 🎉
  9. brucebentley revised this gist Dec 5, 2021. No changes.
  10. brucebentley revised this gist Dec 5, 2021. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    # Setting up the Kubernetes tooling on Windows 10 WSL

    !["Thanks to Panos Sakalakis @meymigrou for making this photo available freely on Unsplash 🎁"](https://images.unsplash.com/photo-1516572783790-114414e34ba4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1000&q=80)

    Nowadays software is build mostly targeting Linux. Life is great as a Mac OS user since we can pretty much install everything through ‘brew’. Unfortunately thing start going pear shape when we have Windows 10 machines as part of the team and the shared tooling just stops working.
    The following post describes how to set up a Windows 10 desktop as a good Kube ready citizen in the Team.

    ## STEP 1:

    _Set up an Ubuntu WSL machine as described below:_


    ## STEP 2:

    _Install the Kube and Docker tools on Ubuntu WSL:_

    ## STEP 3:

    _Connect Kubectl and Docker to the Windows side of things:_

    ## STEP 4:

    _Celebrate!_ 🎉
  11. brucebentley created this gist Dec 5, 2021.
    129 changes: 129 additions & 0 deletions Connecting Docker cli and Kubectl to Docker Desktop for Windows.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,129 @@
    ## Connecting Docker cli and Kubectl to Docker Desktop for Windows

    ### Install Kubectl, Docker, Helm, etc

    > View details here: https://gist.github.com/xynova/87beae35688476efb2ee290d3926f5bb

    ### Setup Docker

    **References:**
    - https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly
    - https://docs.docker.com/docker-for-windows


    1. Open Docker <a href="https://docs.docker.com/docker-for-windows/#docker-settings-dialog" target="_blank">settings dialog</a>.

    2. Under <a href="https://docs.docker.com/docker-for-windows/#general" target="_blank">general</a>, tick
    the `Expose daemon on tcp://localhost2375` option so that we can connect to Docker Daemon from the WSL Ubuntu VM.
    You can later explore options on how to secure the connection even further if you so desire: https://hub.docker.com/r/stefanscherer/dockertls-windows/.

    3. Make sure you <a href="https://docs.docker.com/docker-for-windows/#shared-drives" target="_blank">share your C drive</a>
    so that you can run containers with volumes

    4. Definitely give Docker Daemon <a href="https://docs.docker.com/docker-for-windows/#advanced" target="_blank">more memory</a>.
    Maybe 6GB or more?

    5. <a href="https://docs.docker.com/docker-for-windows/#kubernetes" target="_blank">Enable Kubernetes</a> (if you are not planning to use Minikube).
    Just tick the `Enable Kubernetes` option.

    **IMPORTANT:** Make sure you select the `docker-for-desktop` context through the Docker Desktop for Windows menu so that the `.kube/config` file appropriately configured.




    ### Configure Docker cli

    Back in your WSL ubuntu session configure the cli to talk to the Docker Daemon:

    ```bash
    echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc && source ~/.bashrc
    ```

    Make sure connectivity to the Docker daemon work:
    ```bash
    docker run --rm -ti hello-world
    ```

    Configure Ubuntu to mount windows drives at /c or /e instead of /mnt/c or /mnt/e.
    The options = "metadata" line is not necessary but it will fix folder and file permissions on WSL mounts
    so everything isn’t 777 all the time within the WSL mounts:

    ```bash
    cat << EOF | sudo tee /etc/wsl.conf
    [automount]
    root = /
    options = "metadata"
    EOF
    ```

    **NOTE**: The previous action might take some time to propagate so a full Windows log-off or restart is required.

    Once back, enter an ubuntu session:
    ```bash
    ubuntu

    # ubuntu@windows10:~$
    ```

    Validate drives were mounted at the root:
    ```bash
    ls "/c/Program Files"
    ```

    Now lets run a sample container to make sure volumes are working
    ```bash
    curl https://www.w3.org/Test/test > /c/index.html
    docker run -ti --rm -p 2015:2015 -v /c/index.html:/srv/index.html abiosoft/caddy
    ```


    You can now now browse to <a href="http://localhost:2015/" target="_blank">http://localhost:2015/</a> and should see a Test Dataset page.

    ### Configure Kubectl

    Find your user directory on windows
    ```bash
    ls /c/users
    ```

    Create a soft link to the `.kube/config`. Make sure you replace `<YOUR_USER>` with your username on windows:
    ```bash
    mkdir -p ~/.kube
    ln -sf /c/users/<YOUR_USER>/.kube/config ~/.kube/config
    ```

    Now you should be able to connect to Kubernetes on Docker for Windows
    ```bash
    kubectl cluster-info

    # Kubernetes master is running at https://localhost:6445
    # KubeDNS is running at https://localhost:6445/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
    #
    # To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
    ```

    Test kubectx
    ```bash
    kubectx

    # docker-for-desktop
    ```

    Test kubens
    ```bash
    kubens kube-system

    # Context "docker-for-desktop" modified.
    # Active namespace is "kube-system".

    kubectl get pods

    # NAME READY STATUS RESTARTS AGE
    # etcd-docker-for-desktop 1/1 Running 1 2h
    # kube-apiserver-docker-for-desktop 1/1 Running 1 2h
    # kube-controller-manager-docker-for-desktop 1/1 Running 1 2h
    # kube-dns-86f4d74b45-z7n5h 3/3 Running 3 2h
    # kube-proxy-6568r 1/1 Running 1 2h
    # kube-scheduler-docker-for-desktop 1/1 Running 1 2h
    ```
    131 changes: 131 additions & 0 deletions Enable WSL and Ubuntu 16.04 on Windows 10.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,131 @@
    ## Enable WSL and Ubuntu 16.04 on Windows 10

    **References:**
    - https://docs.microsoft.com/en-us/windows/wsl/install-win10
    - https://docs.microsoft.com/en-us/windows/wsl/install-manual
    - https://docs.microsoft.com/en-us/windows/wsl/user-support
    - https://docs.microsoft.com/en-us/windows/wsl/wsl-config

    ### Install and setup

    Open Powershell in Administrator mode and enable WSL (Needs a computer restart):

    ```Powershell
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
    ```


    Download Ubutnu 16.04 (16.04 has been patched for over a year):

    ```Powershell
    Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile Ubuntu.appx -UseBasicParsing
    ```

    Open Powershell in Administrator mode and install the downloaded package:

    ```Powershell
    Add-AppxPackage .\Ubuntu.appx
    ```

    Now type the following in on the terminal:

    ```Powershell
    ubuntu
    # Installing, this may take a few minutes...
    ```

    #### Setup your default user

    The first user account you create is automatically (https://aka.ms/wslusers) configured with a few special attributes:
    - It is your default user -- it signs-in automatically on launch.
    - It is Linux administrator (a member of the sudo group) by default.
    Type in a Linux username and password for the user.

    **NOTE:** You will need this password to perform `sudo` commands (dont loose it):

    ```Bash
    # Installation successful!
    # Please create a default UNIX user account. The username does not need to match your Windows username.
    # For more information visit: https://aka.ms/wslusers
    # Enter new UNIX username:

    ubuntu

    # Enter new UNIX password:
    password123

    # Retype new UNIX password:
    password123

    # passwd: password updated successfully
    # Default UNIX user set to: ubuntu
    # To run a command as administrator (user "root"), use "sudo <command>".
    # See "man sudo_root" for details.
    ```

    You are now in an ubuntu session:

    ```
    # ubuntu@windows10:~$
    ```

    Having to enter a password when executing sudo commands is a pain so lets remove that.
    **Note** that this is based on the default user being named `ubuntu`.

    ```Bash
    sudo su

    # [sudo] password for ubuntu:

    cat<<EOF > /etc/sudoers.d/ubuntu && chmod 0440 /etc/sudoers.d/ubuntu
    ubuntu ALL=(ALL) NOPASSWD:ALL
    EOF
    ```


    ### Managing distro

    You can manage the Ubuntu instance from a Powershell session:

    ```Powershell
    ubuntu.exe /?
    # Launches or configures a linux distribution.
    #
    # Usage:
    # <no args>
    # - Launches the distro's default behavior. By default, this launches your default shell.
    #
    # run <command line>
    # - Run the given command line in that distro, using the default configuration.
    # - Everything after `run ` is passed to the linux LaunchProcess call.
    #
    # config [setting [value]]
    # - Configure certain settings for this distro.
    # - Settings are any of the following (by default)
    # - `--default-user <username>`: Set the default user for this distro to <username>
    #
    # clean
    # - Uninstalls the distro. The appx remains on your machine. This can be
    # useful for "factory resetting" your instance. This removes the linux
    # filesystem from the disk, but not the app from your PC, so you don't
    # need to redownload the entire tar.gz again.
    #
    # help
    # - Print this usage message.
    ```

    You can also enter an ubuntu shell from other terminal emulators like `Powershell` or `cmd` by typing `ubuntu`:

    ```Powershell
    ubuntu
    # root@windows10:~#
    ```

    You can also change the default user if you want to change it from your previously created one:

    ```Powershell
    ubuntu config --default-user ubuntu
    ```
    171 changes: 171 additions & 0 deletions Installing Kubernetes and Docker tools on Windows 10 Ubuntu WSL.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,171 @@
    ## Installing Kubernetes and Docker tools on Windows 10 Ubuntu WSL

    ### Enter a WSL ubuntu session

    > View details here: https://gist.github.com/xynova/87beae35688476efb2ee290d3926f5bb

    From a Powershell session:

    ```Powershell
    ubuntu
    # ubuntu@windows10:~$
    ```


    ### Install some useful tools

    Install some utilities

    ```bash
    sudo apt-get update -y && sudo apt-get install -y \
    bash-completion \
    nmap \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
    ```


    ### Get Kubectl

    **References:**
    - https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-linux

    Download the latest release with the command:

    ```bash
    curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
    ```

    Make the `kubectl` binary executable and move it into the utilities path::

    ```bash
    chmod +x ./kubectl && sudo mv ./kubectl /usr/local/bin/kubectl
    ```

    Add the completion script to the `/etc/bash_completion.d` directory.

    ```bash
    kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl > /dev/null
    ```

    Force the creation of a temporary `.kube` config directory
    ```bash
    kubectl config set-cluster fake --server=https://5.6.7.8 --insecure-skip-tls-verify
    kubectl config set-credentials nobody
    kubectl config set-context fake --cluster=fake --namespace=default --user=nobody
    ```


    ### Get Helm

    **References:**
    - https://helm.sh/docs/using_helm/#from-script
    - https://github.com/helm/helm/blob/master/docs/helm/helm_completion.md
    - https://github.com/sagansystems/helm-github.git
    - https://github.com/rimusz/helm-tiller
    - https://github.com/maorfr/helm-restore

    Install helm
    ```bash
    curl -LO https://git.io/get_helm.sh
    chmod 700 get_helm.sh
    ./get_helm.sh
    ```

    Add the completion script to the `/etc/bash_completion.d` directory.

    ```bash
    helm completion bash | sudo tee /etc/bash_completion.d/helm > /dev/null
    ```

    Install helm plugins: helm-github, helm-tiller, helm-restore
    ```bash
    helm init --client-only
    helm plugin install https://github.com/sagansystems/helm-github.git
    helm plugin install https://github.com/rimusz/helm-tiller
    helm plugin install https://github.com/maorfr/helm-restore

    ```

    ### Get Kubectx and Kubens

    **References:**
    - https://github.com/ahmetb/kubectx


    Get the `kubectx` script
    ```bash
    curl -O https://raw.githubusercontent.com/ahmetb/kubectx/master/kubectx \
    && chmod +x kubectx \
    && sudo mv kubectx /usr/local/bin/
    ```

    Get the `kubens` script
    ```bash
    curl -O https://raw.githubusercontent.com/ahmetb/kubectx/master/kubens \
    && chmod +x kubens \
    && sudo mv kubens /usr/local/bin/
    ```

    Add the completion script to the `/etc/bash_completion.d` directory.
    ```bash
    BASE_URL=https://raw.githubusercontent.com/ahmetb/kubectx/master/completion
    curl ${BASE_URL}/kubectx.bash | sudo tee /etc/bash_completion.d/kubectx > /dev/null
    curl ${BASE_URL}/kubens.bash | sudo tee /etc/bash_completion.d/kubens > /dev/null
    ```

    ### Get Docker cli and Docker Compose

    **References:**
    - https://docs.docker.com/install/linux/docker-ce/ubuntu/

    Remove older versions of Docker
    ```bash
    sudo apt-get remove docker docker-engine docker.io containerd runc
    ```

    Add Docker’s official GPG key:
    ```bash
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    sudo apt-key fingerprint 0EBFCD88
    ```

    Add Docker's stable repository
    ```bash
    sudo add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"
    ```

    Install Docker cli
    ```bash
    sudo apt-get update -y && sudo apt-get install docker-ce-cli
    ```

    Update pip, install it if not present
    ```bash
    pip --version || sudo apt-get install python-pip
    ```

    Install Docker Compose
    ```bash
    pip install --user docker-compose
    ```

    Add the completion script to the `/etc/bash_completion.d` directory.
    ```bash
    curl https://raw.githubusercontent.com/docker/compose/1.24.0/contrib/completion/bash/docker-compose \
    | sudo tee /etc/bash_completion.d/docker-compose > /dev/null
    ```


    ## Connecting Docker cli and Kubectl to Docker Desktop for Windows


    > View details here: https://gist.github.com/xynova/7d18ccb44eb52a38b5b51c0922e06cc7