Rancher-Desktop

What is Rancher Desktop?

Rancher Desktop is an app that provides container management and Kubernetes on the desktop. Rancher Desktop provides the ability to build, push, and pull container images along with the ability to run containers. This is provided by either the Docker CLI (when you choose Moby/dockerd as you engine) or nerdctl (when you choose containerd as your engine). nerdctl is a “Docker-compatible CLI for containerd” provided by the containerd project. Think of it as an app that envelops other certain Developer tools such as Docker and Kubernetes.

Rancher Desktop Installation

Go to this website to check the download instructions for your specific OS. In case using windows, the instructions are under this Installing Rancher Desktop on Windows heading.

Rancher Instructions for Windows

The releases of various OSs are found here.

Assuming you have already run the Rancher-Desktop executable for your OS, the first interface to appear will look like below. Ensure the Cluster Dashboard button is not greyed out, otherwise this is the first sign of a problem.

Rancher Desktop Interface

You can also check the Diagnostics tab to see everything is working properly.

Click on the Preferences tab.

Rancher Preferences Tab

Ensure the following under Preferences interface match to these settings.

  1. Ensure that in the Preferences>WSL>Integrations that Ubuntu has been checked.

Ubuntu is Checked in Rancher Desktop

  1. Ensure that Preferences>WSL>Network that Enable Network Tunneling is enabled.

Network tunneling

  1. Ensure that in the Preferences>Kubernetes that the Enable Kubernetes and Traefik boxes have been checked. Additionally, ensure that the most stable Kubernetes version is in use.

Traefik is enabled

  1. Ensure that the Preferences>Container Engine>General menu has the dockerd (moby) box checked.

Rancher Container

During installation, Rancher Desktop will (or may) install Kubernetes configurations by default. You can check that the Kubernetes command-line tool, kubectl has been successfully installed by running kubectl version on your terminal.

It is important to check that you are using Rancher Desktop and not any other application to run certain containers, in this case the ML Classifiers. Type kubectl config get-contexts.

If it outputs an asterisk (*) next to rancher-desktop as shown below, you are all good to go.

CURRENT   NAME              CLUSTER           AUTHINFO          NAMESPACE
          minikube          minikube          minikube          default
*         rancher-desktop   rancher-desktop   rancher-desktop   

Additionally, to check that Docker and Rancher Desktop are running alright, run docker ps on your terminal. If some logs starting with CONTAINER ID, IMAGE… headers are printed out, Docker is working fine with Rancher Desktop already installed.

In my case I use Rancher-Desktop and here is a screenshot showing that Rancher is working.

Checking if Rancher is alright

Working with Helm

Helm

What is Helm?

Helm is a tool that streamlines installing and managing Kubernetes applications. Kubernetes is an open source system to deploy, scale and manage containerized applications anywhere. Helm, in a nutshell, simplifies the process of automating the distribution of your applications by using a packaging format called a Helm Chart. Helm manages Helm charts for Kubernetes. Think of a chart as a template for your application.

Helm charts comprise three basic components:

  • The Chart - Chart.yaml defines the application metadata like name, version, dependencies, etc.

  • Values - the values.yaml sets values, which is how you will set variable substitutions for reusing your chart.

  • The templates directory - the templates/ houses your templates and combines them with the values set in your values.yaml file to create manifests.

  • The charts directory - the charts/ stores any chart dependencies you define in Chart.yaml.

Each time you install a Helm chart, you also create an instance of it, called a release.

A Case example of using Helm

The Natural State Impact Portal (NIP) Superset repository contains the dashboard visualization platfrom known as Superset. It is a dashboard for creating Business Intelligence (BI) visualizations.

To have the NIP Superset in your local machine, open VS Code and in the terminal, type:

git clone https://github.com/Natural-State/NIP-Superset.git

This will clone the up-to-date NIP Superset into your local machine.

The branch 3.1.1 will be downloaded by default.

Create a new branch based on the dev branch which is used for active development by running this:

git checkout -b <name-of-your-branch> origin/dev

Ensure you are in the right branch by running:

git branch

This will lead us to the second part, using Helm to deploy superset.

Deploying Superset using Helm

Configurations

In order to be able to upload a sqlite database to Superset Dashboard from whence we will make some visualizations, we will change some parameters inside the helm/superset/values.yaml. In Part 1.1, we mentioned that the values.yaml is used to modify the variables for setting up our chart.

These are modifications to make in our values.yaml to enable it allow loading of sqlite databases.

In line 135 of the helm/superset/values.yaml change it from configOverrides: {} to read as:

configOverrides:
  allow_sqlite_for_examples: |
    PREVENT_UNSAFE_DB_CONNECTIONS = False

Save the file with Ctrl+S.

Pre-deployment

To ensure you are using Rancher Desktop, type this on your terminal:

kubectl config get-contexts

This is because using other Kubernetes related tools such as minikube maybe configured for kubernetes services by default.

An asterisk under the CURRENT column and next to the tool under the NAME column shows which is the tool being used by default. It should read like so:

Default Configurations

If it’s not the case, then change it with

kubectl config use-context rancher-desktop 

If you are redeploying, that is, releasing the Helm Charts all over again, run the following command to clear the namespace.

kubectl delete all --all -n $NAMESPACE 

However, assuming you are starting up for the first time, the helm/.env_example example contains some secret keys that will need to be filled in. Copy these empty secret keys to helm/.env and insert the secret credentials that will provided by your supervisor. Don’t insert the keys in the helm/.env_example file but rather in the helm/.env file. The former is just a template while the latter is the real deal.

Run the command ` openssl rand -base64 42 on your terminal. Copy and past the long output into the SECRET_KEY variable in the helm/.env` file. Everything should look like this:

# Rename the file to .env and fill in the SP information
# env local development
helm_release="superset-release"
HELM_RELEASE="superset-release"
NAMESPACE="superset-namespace"

DOMAIN_NAME=localhost

# To generate a good key you can run: openssl rand -base64 42
SECRET_KEY="<retrieved by running openssl rand -base64 42>"

# Superset SP secrets
SP_CLIENT_SECRET="xxxxxx"
ARM_TENANT_ID="xxxx"
SP_CLIENT_ID="xxxx"

Deployment

Export the local variable environment. Latter Helm commands will read from this environment variables. Run this:

export $(grep -v '^#' ./helm/.env | xargs)

Update helm dependencies:

helm dependency update "./helm/superset"

Some logs will display. To ensure it is successful, the log should read as:

Getting updates for unmanaged Helm repositories...
...Successfully got an update from the "https://helm.traefik.io/traefik" chart repository
...Successfully got an update from the "https://charts.bitnami.com/bitnami" chart repository
...Successfully got an update from the "https://charts.bitnami.com/bitnami" chart repository
Saving 3 charts
Downloading postgresql from repo https://charts.bitnami.com/bitnami
Downloading redis from repo https://charts.bitnami.com/bitnami
Downloading traefik from repo https://helm.traefik.io/traefik
Deleting outdated charts

Thereafter, create a namespace:

kubectl create namespace $NAMESPACE

If for the first time, a new namespace should be created for you. However, if you have done this before: the following output will result.

Error from server (AlreadyExists): namespaces "superset-namespace" already exists

But this is okay indicating that the namespace is already existent.

Deploy superset with local postgres db, you can add the option –dry-run to see check the configuration first. Copy paste and run this:

helm upgrade \
    -n "$NAMESPACE" \
    "$HELM_RELEASE" \
    --install \
    "./helm/superset" \
    -f "./helm/superset/values.yaml" \
    -f "./helm/superset/values.override.yaml" \
    -f "./helm/superset/values.override.local.yaml" \
    --set "extraEnv.BASEURL=http://$DOMAIN_NAME" \
    --set "extraSecretEnv.SECRET_KEY=$SECRET_KEY" \
    --set "extraSecretEnv.SP_CLIENT_SECRET=$SP_CLIENT_SECRET" \
    --set "extraSecretEnv.ARM_TENANT_ID=$ARM_TENANT_ID" \
    --set "extraSecretEnv.SP_CLIENT_ID=$SP_CLIENT_ID" \
    --set "global.postgresql.auth.postgresPassword=superset" \
    --debug

A string of logs should be printed out. To know that running this command was successful, the following should be at the very end of the printed output:

NOTES:
1. Get the application URL by running these commands:
  echo "Visit http://127.0.0.1:8088 to use your application"
  kubectl port-forward service/superset 8088:8088 --namespace superset-namespace

Thereafer run this code:

export $(grep -v '^#' ./helm/.env | xargs)

Preferably in a new terminal, run this code thereafter:

kubectl get pods -n $NAMESPACE

Pods are the basic units for running our application in kubernetes. Each pod represents an instance of that application.

Running the above should print out the following which indicates that the pods are running.

NAME                                        READY   STATUS      RESTARTS   AGE
superset-release-postgresql-0               1/1     Running     0          2m2s
superset-release-traefik-84bc8fc6c8-jsxx5   1/1     Running     0          2m2s
superset-release-redis-master-0             1/1     Running     0          2m2s
superset-release-init-db-gkzmq              0/1     Completed   0          2m2s
superset-release-5f8ff64c9f-kjtkp           1/1     Running     0          2m2s
superset-release-worker-74c58cf865-qr246    1/1     Running     0          2m2s

Finally, run the following to tunnel the port into your local host.

kubectl port-forward service/superset-release 8088:8088 --namespace $NAMESPACE

Go to the following link in a private browser:

localhost:8088/

The Superset dashboard should be visible.

Superset Dashboard