Setting up tools
Kubernetes clusters are typically controlled using tools such as kubectl.
In this tutorial, we'll set up kubectl and access to the training cluster.
kubectl installation
The most up-to-date guides can be found from Kubernetes' documentation site, but in these exercises, we assume you've set up your environment in a particular way.
More details per operating system below.
Note
Make sure you install a version of the kubectl that has the same version as the cluster.
For example, if your cluster uses version 1.21, then you should install kubectl version 1.21.x.
Mac
If you use Mac, follow the instructions for kubectl.
Windows 10
If you use Windows, follow the instructions for kubectl.
Another option for Windows is to set up WSL version 2 (aka WSL2), if you haven't done so already. WSL allows you to run a Linux operating system within your Windows environment.
After that, you should be able to follow the Linux installation procedure below.
Linux
If you use Linux, follow the instructions for kubectl.
Command-line environment
kubectl is a very command-line centric tool and in the exercises there are a lot of terminal commands being run.
Therefore, in order to complete the exercises, you must use a similar command-line environment to run various kubectl related commands. More details per operating system below.
Mac
Mac OS is a Unix-like operating system at core and therefore it has many compatible command-line utilities pre-installed. While Mac OS is not a Linux distribution, its tools are compatible enough with a Linux environment for the purpose of the exercises.
You can access the command line using the Terminal application in Mac. Alternatively, you can choose to use one of the many other terminal applications such as iTerm2.
In the latest versions of Mac OS, the Terminal opens ZSH shell as the command-line interface, which is enough for completing the exercises. However, you can also install and use Bash shell using Brew (or another similar package manager), if you prefer using it.
Windows 10
On Windows 10, the exercises work with PowerShell. Your mileage may vary with Windows CMD, so we recommend either PowerShell or WSL.
With WSL, you get the benefits of Linux shell capabilities. These are very suitable for working with kubectl. WSL is also required to run Docker and containers on Windows.
We recommend using the Windows Terminal for accessing the command-line interface of your WSL environment.
Most Linux distributions available for WSL use Bash shell as the default command-line interface in terminal, which is enough for completing the exercises. However, you can also install and use ZSH shell using the package manager available in your WSL environment, if you prefer using it.
Linux
All desktop Linux distributions have some terminal application pre-installed (e.g. GNOME Terminal, KDE Konsole, Terminator, Tilix, xterm). You can use which ever terminal application on Linux you can get your hands on.
Most Linux distributions use Bash shell as the default command-line interface in terminal, which is enough for completing the exercises. However, you can also install and use ZSH shell using your Linux distribution's package manager, if you prefer using it.
Configuring kubectl access
Access to Kubernetes from kubectl is done via a kubeconfig file.
If you're participating in one of Polar Squad's workshops, the instructors will provide you this configuration file.
To use the configuration file with kubectl put the configuration file into your home directory.
Alternative is that you can set the KUBECONFIG
environment variable to point to the file, or provide the --kubeconfig=/path/to/tutorial-kubeconfig.yaml
flag for each of the commands you run.
Linux, WSL and macOS
The directory is $HOME/.kube
, and the name of the file should be config
.
Windows
The directory is $env:USERPROFILE\.kube
, and the name of the file should be config
.
Test cluster access
We should now be able to access the training cluster using kubectl.
First, check the version so it matches the cluster:
$ kubectl version --client
Your instructor will advise on the needed versions. In this case, 1.21.2 is correct and matches the cluster:
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.2", GitCommit:"092fbfbf53427de67cac1e9fa54aaa09a28371d7", GitTreeState:"clean", BuildDate:"2021-06-16T12:52:14Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"darwin/amd64"}
Now, we can test the access by running any command that interacts with the cluster.
List all nodes attached to the cluster:
$ kubectl get nodes
If the command was successful, you should see something like this:
NAME STATUS ROLES AGE VERSION
ip-10-0-3-68.us-east-2.compute.internal Ready <none> 6d19h v1.21.2-eks-55daa9d
Note
However, since the user accounts can be limited in what they can do in the cluster, you may also see an error.
Error from server (Forbidden): nodes is forbidden: User "system:serviceaccount:example-user:example-user" cannot list resource "nodes" in API group "" at the cluster scope
This is normal and just shows that your cluster administrator is a bit strict. You should be able to list some Pods, to be able to do some actual work:
$ kubectl get pods
The namespace may be empty, so you will see this:
No resources found in example-user namespace.
But no fear, we can see that the API calls are working. Let's continue!
Optional: GUI tools
We'll be primarily using kubectl to work with the training cluster, but you might find it useful to view your Kubernetes resources through graphical user interface.
As you follow along the exercises, you can use either one of these GUI tools to view what's happening in your cluster.
Installation of these tools is optional.
Octant
Octant aims to be a development tool that helps you understand what resources you're running in your cluster and their state is. It runs locally on your machine and uses your Kubernetes credentials to access the clusters.
To install Octant, follow the official installation steps provided in the Octant homepage.
Once you've installed the tool, you can launch it by running the command octant
in your terminal.
This will launch a local web server in the address http://127.0.0.1:7777 where Octant will be available.
Lens
Lens is described as an IDE for Kubernetes. Its features are very similar to what Octant has.
The main different between Octant and Lens is that Lens is a desktop app instead of a local web server.
To install Lens, follow the official installation steps.
Note that Lens comes with telemetry enabled by default. If you wish to disable the telemetry, follow these steps:
- Open Lens
- Select "File" from the toolbar
- Select "Preferences"
- Disable the option "Allow telemetry & usage tracking"
Optional: Other useful tools
There's a couple of other tools you might find handy during your journey with Kubernetes.
These tools are also optional.
kubectx and kubens
In the future, you might end up working with multiple Kubernetes clusters and namespaces.
You can switch between the clusters and namespaces using kubectl config
command, but you'll most likely find it a bit cumbersome to use.
For this purpose, it's recommended to install kubectx and kubens.
Follow the official installation instructions to install the two tools.
K9s
K9s provides a terminal UI to interact with your Kubernetes clusters.
K9s makes it easy to navigation easy in your Kubernetes cluster.
Check K9s here: https://github.com/derailed/k9s
Minikube
In these exercises, we'll be using a cloud-hosted Kubernetes cluster but it might come in handy to be able to experiment with Kubernetes on your computer. This is where Minikube comes handy.
Minikube is a tool for quickly setting up a small local Kubernetes cluster on Linux, Mac, and Windows.
Check the official guide for getting started with Minikube.
Kubernetes in Docker for Desktop
Docker for Desktop on Mac and Windows ships with Kubernetes, too.
Here's how you can enable Kubernetes on your computer running Docker for Desktop:
Next
In the next section, we'll learn how to run some containers in Kubernetes.