k3s.io is a full operating kubernets environment that can help you to run your deployments for example at your laptop. It is more lightweight than microk8s or minikube.
K3s get its lightweight goal by removing features out of the Kubernetes binaries (legacy, alpha, and cloud-provider-specific features), also use containerd instead of docker, use sqlite3 as database instead of etcd.
FEATURES:
- k3s binary: 52Mb
- containerd instead of docker
- Helm Chart support
- sqlite3 database ( support for other databases )
- local storage class provisioner
In this post we will see how to set up a local development environment with this components:
- k3s as kubernetes control-plane.
- traefik as ingress controller.
First we cant deploy k3s on your local with this command:
curl -sfL https://get.k3s.io | sh -s - --disable=servicelb --disable=traefik
As you can see, we are going to disable 2 components of the default k3s installation, servicelb because I am going to use
traefik as service mesh controller, but I prefer to install it later to adapt all the options to my environment, for that --disable=traefik
is appended to the installation command.
When the installation process is complete, we need to verify that all control-plane components are running. You can use k3s command or kubectl
With k3s you can use directly kubectl with the admin credentials, no need to copy or create any service-account
root@zbox:~# k3s kubectl get pod --namespace kube-system
NAME READY STATUS RESTARTS AGE
metrics-server-7b4f8b595-rxbdb 1/1 Running 1 26d
coredns-66c464876b-2jnbn 1/1 Running 1 26d
local-path-provisioner-7ff9579c6-lht8c 1/1 Running 6 26d
if you want to use kubectl from your machine to the server where you have installed it, you can copy that config manifest located at /etc/rancher/k3s/k3s.yaml
to your laptop at ~/.kube/config
but you need to edit the config file and change the next param:
server: https://127.0.0.1:6443
with
server: https://192.168.1.222:6443
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: AbcdefgJSUJkekNDQVIyZ0F3SUJBZ0lCQURBS0JnZ3Foa2pPUFFRREFqQWpNU0V3SHdZRFZRUUREQmhyTTNNdGMyVnkKZG1WeUxXTmhRREUyTURZMk56VTVPRE13SGhjTk1qQXhNVEk1TVRnMU16QXpXaGNOTXpBeE1USTNNVGcxTXpBegpXakFqTVNFd0h3WURWUVFEREJock0zTXRjMlZ5ZG1WeUxXTmhRREUyTURZMk56VTVPRE13V1RBVEJnY3Foa2pPClBRSUJCZ2dxaGtqT1BRTUJCd05DQUFTTDZGdnNZRkZXK3NYZjNZWjFRQnEyRDBRa1JKMWVsTGJtQjdhMExaaWoKclRGRVBHRHA4MFdVcko5RjBRcEtzQjVoMlVKY3lQeDl32342TRvMEl3UURBT0JnTlZIUThCQWY4RQpCQU1DQXFRd0R3WURWUjBUQVFIL0JBVXdBd0VCL3pBZEJnTlZIUTRFRmdRVTU3b2lMMFRxaFZIb0UvY3Y4S1kxCkh1U2U2S293Q2dZSUtkjhKJHkrfwerUUloQU1VK1dEakEwb1FqSkllU3NWSVdwOW1Bd2JCNVZxYmQKYmEyVThUWnZlcnhkQWlBell0NzZ2djhHenhDTGNsZHJaalpheXNmSm04UzhZeXErbkM5WkpPc3o4Zz09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
server: https://1192.168.1.222:6443
Now you can use kubectl from your local machine to connect the remote k3s server:
vmalaga@laptop:~# kubectl -n kube-system get po
NAME READY STATUS RESTARTS AGE
metrics-server-7b4f8b595-rxbdb 1/1 Running 1 26d
coredns-66c464876b-2jnbn 1/1 Running 1 26d
local-path-provisioner-7ff9579c6-lht8c 1/1 Running 6 26d
vmalaga@laptop:~# kubectl -n kube-system get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-dns ClusterIP 10.43.0.10 <none> 53/UDP,53/TCP,9153/TCP 26d
metrics-server ClusterIP 10.43.141.121 <none> 443/TCP 26d
In the next post we are going to see how to install traefik load balancer to use it as a routing method to any application that we install at our kubernetes environment