Deploy K8s Cluster in Minutes with k3s
K3S is a lightweight and certified Kubernetes distribution, perfect for run development environments, CI/CD and IoT. It works very well with the ARM architecture. It’s packaged to a single binary that makes deployment and setup easy.
The default installation comes with:
- embedded SQLite
- containerd
- flannel
- coredns
- traefik (ingress controller)
- local path provisioner
- service load balancer
All those features are more than enough for most use-cases. Of course, installation is fully configurable, so if you want etcd, docker, Nginx ingress and so on - go to official documentation page https://rancher.com/docs/k3s/latest/en/ .
Default installation
Login to machine and run:
curl -sfL https://get.k3s.io | sh -and that’s it…
After a few seconds, you should see that the master node is ready with k3s kubectl get node.
You will find config.yaml for kubernetes in /etc/rancher/k3s/k3s.yaml
Advanced installation with nginx-ingress, metallb and cert-manager
-
Deploy k3s without traefik and servicelb
Terminal window curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC=" --no-deploy=servicelb --no-deploy=traefik" sh -s - -
Get config from
/etc/rancher/k3s/k3s.yamland put into~/.kube/configon your machine -
Terminal window curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash -
Add helm repo and update
Terminal window helm repo add stable https://kubernetes-charts.storage.googleapis.com/helm repo update -
Install metallb. Range of available ip addresses for loadbalancer are set in
configInline.address-pools[0].addresses[0].Terminal window helm install --namespace=kube-system \--set configInline.address-pools[0].name=default \--set configInline.address-pools[0].protocol=layer2 \--set configInline.address-pools[0].addresses[0]=192.168.1.10-192.168.1.50 \metallb stable/metallb -
Install nginx-ingress
Terminal window helm install --namespace=kube-system \--set rbac.create=true \nginx-ingress stable/nginx-ingress -
Install and configure certmanager for lets-encrypt
Terminal window kubectl apply -f https://raw.githubusercontent.com/jetstack/cert-manager/release-0.14/deploy/manifests/00-crds.yamlhelm install --namespace=kube-system cert-manager stable/cert-managercat <<EOF | kubectl apply -f -apiVersion: cert-manager.io/v1alpha2kind: ClusterIssuermetadata:name: letsencryptspec:acme:server: https://acme-v02.api.letsencrypt.org/directoryemail: ACME_EMAILprivateKeySecretRef:name: letsencryptsolvers:- dns01:cloudflare:email: CLOUDFLARE_EMAILapiKeySecretRef:name: cloudflare-apikey-secretkey: CLOUDFLARE_APIKEYselector:dnsNames:- 'DOMAIN_NAME'EOFWhere:
- ACME_EMAIL - some email in yor domain (will be used to limit number of requests to acme)
- CLOUDFLARE_EMAIL - email of your cloudflare account
- CLOUDFLARE_APIKEY - api key to your cloudflare account
- DOMAIN_NAME - domain that will be used in lets-encrypt certs (eg.:
*.rycerz.co)
Important disclaimer
Don’t deploy everything in kube-system if it’s not test/development cluster. Be safe.