K3s is an open-source, lightweight Kubernetes distribution by Rancher that was introduced this year and has gained huge popularity. If you’re not familiar with it, check out this post on k3s vs k8s by Andy Jeffries, CTO at Civo. People not only like the concept behind it, but also the awesome work that the team has done to strip down the heavy Kubernetes distribution to a minimal level. Though k3s started as a POC project for local Kubernetes development, its development has led people to use it even at a production level.
Official GitRepo: https://github.com/rancher/k3s
Seeing the popularity of k3s, many developers/companies have started building products around k3s. CIVO cloud has come up with a cloud offering for First-Ever Managed k3s Kubernetes cluster.
CIVO Kubernetes Offering:
CIVO cloud has created a lightweight Kubernetes managed cluster offering.
Let us take a walk through some of the features of this managed k3s cluster and deploy a sample application.
NOTE: Before proceeding make sure you have the following:
- A Civo cloud account (they also have a 50$ free credit), you can sign up here.
- Civo cli tool installed: Civo cli is a command-line tool for interacting with resources in Civo Cloud. It's very handy and useful as you do not need to go to UI and can do most of the tasks from the Civo cli itself. For installation, you Need Ruby Installed in your machine (v 2.0.0 or later) and then run :
sudo gem install civo_cli
For more info visit: https://github.com/civo/cli
Civo Cloud has a managed k3s Kubernetes cluster offering and we can spin up the whole cluster using civo cli itself
Step1: Civo cli account setup using api keys
civo apikey add saiyam <yourkey>
Saved the API Key
<yourkey> as Demo_Test_Key
you can find your api key from: cloud account settings > Security > API Key (https://www.civo.com/account/security)
Set the apikey as the default key to connect to Civo resources:
civo apikey current saiyam
You can list all stored API keys in your configuration by invoking
civo apikey list or remove one by name by using
civo apikey remove apikey_name
Step2: Create a Kubernetes Cluster using CIVO cli
command: civo kubernetes create civofirst --wait --saveBuilding new Kubernetes cluster civofirst: Done
Created Kubernetes cluster civofirst in 01 min 30 sec
Merged config into ~/.kube/configcommand: civo kubernetes list
While creating the cluster using civo CLI you have a few options that can be provided :
wait: spins until the cluster comes in ready state
save: saves the kubeconfig file
nodes: the number of nodes to be created, by default 3 nodes are created and master is counted as a node.
size: the size of the nodes, default size is g2.medium
So that is it you have just launched a 3 node k3s cluster running Kubernetes version 1.14
k3s Deployment and service:
Now that we have created k3s cluster lets see some basic deployment of nginx image and exposing it as a service.
kubectl get nodesNAME STATUS ROLES AGE VERSIONkube-master-3872 Ready master 29m v1.14.6-k3s.1kube-node-6052 Ready worker 29m v1.14.6-k3s.1kube-node-eaf0 Ready worker 26m v1.14.6-k3s.1kubectl get pods --all-namespacesNAMESPACE NAME READY STATUS RESTARTS AGEkube-system coredns-b7464766c-89nrt 1/1 Running 0 29mkube-system helm-install-traefik-g59pl 0/1 Completed 0 29mkube-system svclb-traefik-689lv 2/2 Running 0 29mkube-system svclb-traefik-bhg8h 2/2 Running 0 29mkube-system svclb-traefik-xpf46 2/2 Running 0 27mkube-system traefik-5c79b789c5-ns6xj 1/1 Running 0 29m
Now let us deploy a sample nginx application, service, and ingress:
Deployment: kubectl apply -f deploy.yaml
- image: nginx
Service: kubectl apply -f svc.yaml
- name: http
Ingress: kubectl apply -f ingress.yaml
- host: nginx.localhost
- path: /
Let us see what all has been created.
kubectl get deployNAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 2/2 2 2 4m3skubectl get svcNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes ClusterIP 192.168.128.1 <none> 443/TCP 153mnginx-service LoadBalancer 192.168.139.191 172.31.3.106,172.31.3.157,172.31.3.159 8080:30051/TCP 3m16skubectl get ingressNAME HOSTS ADDRESS PORTS AGEnginx-ingress nginx.localhost 172.31.3.106 80 3m44s
Now open the browser and access the service by NodeIp:30051
You have deployed a sample application and created a service accessible from the internet within minutes with prepackaged ingress controller -> Traefik that comes packaged with k3s managed Kubernetes cluster by Civo cloud.
Civo cli commands :
Scaling the cluster: Cluster can be scaled up to the quota and down to 1 via UI or civo cli
civo kubernetes scale civofirst --nodes=4Kubernetes cluster civofirst will now have 4 nodes
Renaming the cluster:
civo kubernetes rename civo --name="Prod"Kubernetes cluster 27f587bc-587b-48b2-8302-3fd62baeff76 is now named Prod
Removing the cluster:
civo kubernetes remove ProdRemoving Kubernetes cluster Prod
Marketplace: Civo cloud has an extensive list of application with the one-click install from the UI. You can go to UI and select the app that you want to deploy to the cluster and it will be available within minutes. Let us try to deploy OpenFaas on k3s from the marketplace.
Select OpenFaaS and click Install Apps, within a few seconds you can see it appears in the Installed apps section with instructions as well to deploy a sample function.
You can access the OpenFaaS UI by NODE_IP:31112 and enter the username/password.
Here we just deployed a sample colorise function to convert image to black & white image.
From the command line, you can see below objects created in k3s cluster when you deployed the OpenFaaS application from the marketplace.
kubectl get all -n openfaasNAME READY STATUS RESTARTS AGEpod/alertmanager-85864b8547-qb5zb 1/1 Running 0 27mpod/basic-auth-plugin-85994747dd-rvfds 1/1 Running 0 27mpod/faas-idler-6568bb4c9b-5xfjz 1/1 Running 2 27mpod/gateway-dcdd5b79c-rnfdj 2/2 Running 0 27mpod/nats-d4c9d8d95-fjw89 1/1 Running 0 27mpod/prometheus-855d56876d-txscc 1/1 Running 0 27mpod/queue-worker-56b64d6848-48b7w 1/1 Running 0 27mNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEservice/alertmanager ClusterIP 192.168.214.254 <none> 9093/TCP 27mservice/basic-auth-plugin ClusterIP 192.168.162.218 <none> 8080/TCP 27mservice/gateway ClusterIP 192.168.146.141 <none> 8080/TCP 27mservice/gateway-external NodePort 192.168.212.52 <none> 8080:31112/TCP 27mservice/nats ClusterIP 192.168.164.158 <none> 4222/TCP 27mservice/prometheus ClusterIP 192.168.194.224 <none> 9090/TCP 27mNAME READY UP-TO-DATE AVAILABLE AGEdeployment.apps/alertmanager 1/1 1 1 27mdeployment.apps/basic-auth-plugin 1/1 1 1 27mdeployment.apps/faas-idler 1/1 1 1 27mdeployment.apps/gateway 1/1 1 1 27mdeployment.apps/nats 1/1 1 1 27mdeployment.apps/prometheus 1/1 1 1 27mdeployment.apps/queue-worker 1/1 1 1 27mNAME DESIRED CURRENT READY AGEreplicaset.apps/alertmanager-85864b8547 1 1 1 27mreplicaset.apps/basic-auth-plugin-85994747dd 1 1 1 27mreplicaset.apps/faas-idler-6568bb4c9b 1 1 1 27mreplicaset.apps/gateway-dcdd5b79c 1 1 1 27mreplicaset.apps/nats-d4c9d8d95 1 1 1 27mreplicaset.apps/prometheus-855d56876d 1 1 1 27mreplicaset.apps/queue-worker-56b64d6848 1 1 1 27m
Summary: Civo Kubernetes service is lightweight k3s managed cluster for production-ready workloads, currently in beta as they are improving the features based on community feedback via the KUBE100 program. Things we discussed in this article:
- Introduction to k3s and managed k3s
- Civo CLI
- Cluster creation/scaling/renaming/removing using Civo cli
- Deploying a sample application & exposing it to the outside world
- Deploying OpenFaaS application from Marketplace