1.3 Set Up Environment

1.3: Kubernetes Development Environment Setup


This guide will help you set up a Kubernetes development environment on your Windows machine using WSL and RKE2.

Please familiarize yourself with this process and these commands. If something doesn't make sense to you, don't just do it and move on. Seek answers, confirmation, and assistance to further your understanding about Kubernetes.

Before you start, if you happen to run a command and you see "command not found," all it typically requires is a sudo apt install [package] and it usually provides that in the output, unless you misspelled.

This guide will assume you already have a functional Linux environment available as setting it up can be found within the documentation that pertains to your specific environment.

Options that are available:

  • WSL
  • Virtualization (HyperV, VMWare, etc.)
  • Bare Linux

Before You Start

If you are unfamiliar with linux or CLI commands, please do your due diligence and learn those. Please don't put random files where they shouldn't be, either. Usually I put mine in my user folder /home/goblincoln/. Please be careful when deleting or modifying files.
Linux Commands Cheat Sheet!


1. Install Kubernetes

RKE2 (Rancher Kubernetes Engine - Government)

RKE2 is a hardened version of Kubernetes, often used in government environments. My tutorial will focus on using this until I provide documentation for the others.


2. Access Kubernetes Executables

We’ll make kubectl, crictl, and ctr available system-wide or for your user.

Commands You’ll Use

  • ls
  • cp
  • chown user:user (The first user sets the owner, the second user sets the group. This example gives your user full control)
  • chmod (Look up documentation on this. It shouldn't be used freely. We probably want to give our files execute permissions for our user)
  • Subcommands:
    • -R (recursive)
    • -a (show all)

Steps

  1. Locate the executables within the RKE2 bin folder on your machine:
    /var/lib/rancher/rke2/bin
  2. Copy kubectl to your desired bin directory:
    • For all users, copy into: /usr/local/bin
  3. Test by running:
    kubectl version
    Kubectl

3. Configure kubectl for access and K9s integration

  1. Locate your rke2.yaml config file. This is what grants us the proper connection to our cluster:
    /etc/rancher/rke2/rke2.yaml
  2. Create a .kube directory in your home folder:
    mkdir -p ~/.kube
  3. Copy the config file:
    sudo cp /etc/rancher/rke2/rke2.yaml ~/.kube/config
  4. Change ownership:
    sudo chown youruser:youruser ~/.kube/config

4. Update Your .bashrc for Convenience

Add the following lines to your ~/.bashrc:

alias kubectl="kubectl --kubeconfig /home/YOURUSERNAME/.kube/config"
alias ctr="sudo /var/lib/rancher/rke2/bin/ctr --address /run/k3s/containerd/containerd.sock --namespace k8s.io"
alias k=kubectl
export KUBE_EDITOR=my_fav_editor
  • Replace YOURUSERNAME with your actual username.
  • KUBE_EDITOR can be whatever you prefer. For example, if you wish to use kubectl edit on something, it will default to vim. This lets you choose nano if you're more comfortable with it.
  • Explanation: alias ctr="sudo /var/lib/rancher/rke2/bin/ctr --address /run/k3s/containerd/containerd.sock --namespace k8s.io" is how to interact with our Kubernetes image store. I stated earlier that RKE2 uses containerd, so you have to ensure you are connected to that address. It also stores our images in the K8s namespace. Adding this to the .bashrc file will allow us to access our local image registry/store by typing in ctr. This is necessary in air-gapped environments or if you do not have an image stored on a public registry.

Tip: Use nano, vi, or vim to edit .bashrc. Example:

nano ~/.bashrc

Apply changes:

exec bash

or close and reopen your terminal.


5. Other installs

  • k9s: Terminal-based UI for Kubernetes. I HIGHLY recommend this CLI-based GUI. I do advise you practice using the CLI commands though.
    • GitHub for Installation
    • Download and install per instructions on their page or go to the GitHub link for targeted installation instructions (For Ubuntu/other Linux distros).
    • Type k9s in your terminal to see if it works!
  • helm: Kubernetes package manager. You will need this for Module 3.
    curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null
    sudo apt-get install apt-transport-https --yes
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
    sudo apt-get update
    sudo apt-get install helm 
    

You should end up with these results if everything is working:

K8s Working CLI K8s Working K9s

Notes

  • Practice using the command line for better muscle memory.
  • Both kubectl and k9s are effective; use what works best for you. We might not always have k9s, but we will always have kubectl.