How does one run containers on k3s? Here are a few things I did to play around with my cluster.
The following syntax describes how to run kubectl
commands from the terminal:
kubectl [command] [TYPE] [NAME] [flags]
command
specifies the operation to be performedTYPE
specifies the resource type (e.g. pod, node, deployment, service)NAME
specifies the name of the resourceflags
specifies optional flagsDocumentation: kubectl run
BusyBox is a suite of tools for Linux that provides a shell interface. The image is useful for testing as a running container because the image is lightweight. I used the following command to ephemerally run the container on k3s:
k3s kubectl run -it --rm --restart=Never busybox-test --image=busybox sh
k3s
: CLI for k3skubectl
: CLI for Kubernetes (wrapped by k3s)run
: kubectl command-it
: make the container interactive-rm
: delete the pod after it exits. Only valid when attaching to the container, e.g. with ‘–attach’ or with ‘-i/–stdin’--restart=Never
: do not restart the container upon exitbusybox-test
: the resource name (used by k8s)--image=busybox
: specifies busybox
as the image to build the containersh
: requests sh
access to busybox
shell in containerDid you know there was a package manager for Kubernetes clusters? Helm is a tool useful for installing Charts which is a Helm package containing all resource definitions necessary to run some application, tool, or service on a k8s cluster. In addition to Charts, Helm also embodies two other concepts: a Repository is the place where charts can be collected and shared and a Release is an instance of a chart running on a k8s cluster. From the Helm intro: “Helm installs charts into Kubernetes, creating a new release for each installation. And to find new charts, you can search Helm chart repositories.”
Using Helm, I can leverage my k3s cluster by making use of existing Helm charts.
I want to run a simple VPN server on my network. It won’t handle crazy traffic and I’m mostly trying this just for the sake of learning.
First, I installed Helm
to node1
so that I could use the openvpn-as helm chart. I used the following command to add charts from stenic
to the Helm package repositories:
helm repo add stenic https://stenic.github.io/helm-charts
The next command deploys the container:
helm install openvpn-ml --set "service.type=LoadBalancer" stenic/openvpn-as
I initally encountered this error after running the helm install
command:
Error: INSTALLATION FAILED: Kubernetes cluster unreachable: Get "http://localhost:8080/version": dial tcp [::1]:8080: connect: connection refused
The error stems from Helm trying to make use of the same configuration file used by Kubernetes. Since I am running k3s, the following command sets the KUBECONFIG
environment variable to point to the k3s configuration:
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
Now, Helm should be able to install the chart and make use of the k3s cluster.
I was not able to get OpenVPN properly set up as the pod running OpenVPN Access Server has a status of CrashLoopBackoff
but it does appear that the chart was able to deploy 12 running pods.