k3s hosted in Civo - Part 2.0

Posted on November 02, 2020 in DevOps

This blog is part of a serie:

Intro

Civo offers a hosted k3s cluster with an app market: civo/kubernetes-marketplace, like Arkade.

At time of writing Civo k8s is in beta. You can apply for $70 monthly free service.

You can work with Civo from

From those you create a k8s cluster.
Then you download the kubeconfig and continue work on that remote cluster via your local installed kubectl.

Prerequisites

You must have kubectl installed.

Get started - using apps from Civo's k8s marketplace

  • First you download civo cli and save it into C:\Program Files\Civo.
  • Next add that path to environment path.
  • Test civo:
# is civo reachable?
civo version
# Civo CLI v0.6.39

Get API key

# save API key into civo CLI
civo apikey add My_Api_Key DAb75oyqVeaE7BI6Aa74FaRSP0E2tMZXkDWLC9wNQdcpGfH51r
# Saved the API Key DAb75oyqVeaE7BI6Aa74FaRSP0E2tMZXkDWLC9wNQdcpGfH51r as My_Api_Key

# Set the key as current
civo apikey current My_Api_Key
# The current API Key is now My_Api_Key

# help me create a cluster
civo k8s create -h
# create a cluster and wait for it to finish
civo k8s create Cluster-1-just-dashboard --size=g2.xsmall --nodes=1 --wait -a=kubernetes-dashboard

# print kube config for the created cluster
civo k8s config Cluster-1-just-dashboard
# apiVersion: v1
# clusters:
# - cluster:
#   name: cluster-1-just-dashboard

# save (or merge) the config into your kubeconfig
civo k8s config Cluster-1-just-dashboard --save
# Saved config to ~/.kube/config

# print nodes and apps in your cluster
civo k8s show Cluster-1-just-dashboard
#           ID : 18779094-3e4e-4db5-85d4-6294c5ffffff
#         Name : Cluster-1-just-dashboard
#        Nodes : 1
#         Size : g2.xsmall
#       Status : ACTIVE
#      Version : 1.18.6+k3s1
# API Endpoint : https://91.211.144.244:6443
#    Master IP : 91.211.144.244
# DNS A record : 18779094-3e4e-4db5-85d4-6294c5ffffff.k8s.civo.com

# Nodes:
# +------------------+----+--------+-----------+-----------+------+----------+
# | Name             | IP | Status | Size      | Cpu Cores | Ram  | SSD disk |
# +------------------+----+--------+-----------+-----------+------+----------+
# | kube-master-5cbc |    | ACTIVE | g2.xsmall |         1 | 1024 |       25 |
# +------------------+----+--------+-----------+-----------+------+----------+
# Applications:
# +----------------------+---------+-----------+------------+
# | Name                 | Version | Installed | Category   |
# +----------------------+---------+-----------+------------+
# | kubernetes-dashboard | v2.0.0  | true      | management |
# +----------------------+---------+-----------+------------+

With the cluster up browse to
https://www.civo.com/account/kubernetes/18779094-3e4e-4db5-85d4-6294c5ffffff
and expand kubernetes-dashboard. It will tell you howto connect:

# Get login token
kubectl -n kubernetes-dashboard describe secret admin-user-token | grep ^token
# get api access
kubectl proxy

# Open dashboard in browser
start http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
# Signin and paste token

You can add more apps out of the box:

# Print the apps you can install
civo k8s applications list
# +---------------------------+------------------+--------------+-----------------+-----------------------------+
# | Name                      | Version          | Category     | Plans           | Dependencies                |
# +---------------------------+------------------+--------------+-----------------+-----------------------------+
# | argo                      | (default)        | ci_cd        |                 |                             |
# | cert-manager              | v1.0.2           | architecture |                 | Helm                        |
# | docker-registry           | ALPHA            | architecture |                 | Helm, cert-manager, Traefik |
# | dynamic-pv-scaler         | 0.1.0            | storage      |                 | prometheus-operator         |
# | Ghost                     | 3.35.5           | management   | 5GB, 10GB, 15GB | longhorn                    |
# | gitea                     | 1.12.5           | management   |                 |                             |
# | haproxy                   | 1.4.6            | architecture |                 |                             |
# | Helm                      | 2.16.5           | management   |                 |                             |
# | Jaeger-Operator           | 1.2.0            | monitoring   |                 |                             |
# | Jenkins                   | 2.190.1          | ci_cd        | 5GB, 10GB, 20GB | Longhorn                    |
# | keptn                     | 0.7.1            | ci_cd        |                 |                             |
# | kube-hunter               | latest           | security     |                 |                             |
# | kube-scan                 | v20.5            | security     |                 |                             |
# | KubeDB                    | v0.12.0-r1       | database     |                 | Longhorn                    |
# | Kubei                     | 1.0.7            | security     |                 |                             |
# | Kubeless                  | 1.0.5            | architecture |                 |                             |
# | kubernetes-dashboard      | v2.0.0           | management   |                 |                             |
# | Linkerd                   | Latest           | architecture |                 |                             |
# | loki-stack                | v0.41.2          | monitoring   |                 | prometheus-operator         |
# | Longhorn                  | 1.0.2            | storage      |                 |                             |
# | Maesh                     | Latest           | architecture |                 | Helm                        |
# | MariaDB                   | 10.4.7           | database     | 5GB, 10GB, 20GB | Longhorn                    |
# | metrics-server            | (default)        | architecture |                 |                             |
# | MinIO                     | 2019-08-29       | storage      | 5GB, 10GB, 20GB | Longhorn                    |
# | MongoDB                   | 4.2.0            | database     | 5GB, 10GB, 20GB | Longhorn                    |
# | Netdata                   | Latest           | monitoring   |                 | Helm                        |
# | Nginx                     | latest           | architecture |                 |                             |
# | OpenFaaS                  | 0.18.0           | architecture |                 | Helm                        |
# | permission-manager        | 1.6.0            | management   |                 |                             |
# | Polaris                   | 1.2.0            | security     |                 |                             |
# | Portainer                 | ce               | management   |                 |                             |
# | PostgreSQL                |             11.5 | database     | 5GB, 10GB, 20GB | Longhorn                    |
# | prometheus-operator       | 0.35.0           | monitoring   |                 |                             |
# | RabbitMQ                  | 3.8.8-management | architecture |                 |                             |
# | Rancher                   | v2.5.0           | management   |                 |                             |
# | Redis                     |              3.2 | database     |                 |                             |
# | sealed-secrets            | v0.12.4          | architecture |                 |                             |
# | Selenium                  | 3.141.59-r1      | ci_cd        |                 |                             |
# | system-upgrade-controller | v0.6.2           | architecture |                 |                             |
# | Tekton                    | v0.17.0          | ci_cd        |                 |                             |
# | Traefik                   | (default)        | architecture |                 |                             |
# | Traefik-v2                |              2.3 | architecture |                 |                             |
# | Wordpress                 | 5.5.1            | management   | 5GB, 10GB, 20GB | longhorn, mariadb:5GB       |
# +---------------------------+------------------+--------------+-----------------+-----------------------------+

civo kubernetes applications add PostgreSQL --cluster=Cluster-1-just-dashboard
# You requested to add PostgreSQL but didn't select a plan. Please choose one... (5GB, 10GB, 20GB) [5GB]: 5GB
# Thank you, next time you could use "PostgreSQL:5GB" to choose automatically
# Added PostgreSQL 11.5 to Kubernetes cluster Cluster-1-just-dashboard

And finally - tear down and stop costs:

# Delete cluster
civo kubernetes remove Cluster-1-just-dashboard
# The Kubernetes cluster called Cluster-1-just-dashboard with ID 18779094-3e4e-4db5-85d4-6294c5ffffff was deleted

Hosting your own image in Civo

If you read Part 1.3: Run containers in k8s, then you probably want to host your image in Civo. In that previous lab the image was hosted on your own dev PC. Now we want to host it in the cloud instead.

We created a k8s-deploy-dev.yml for deploying the image. We will just use that same yaml for deploying to another host.
Cool or what :-)

So lets repeat creating a civo cluster (this time I'll omit the dashboard):

# help me create a cluster
civo k8s create -h
# create a cluster and wait for it to finish
civo k8s create Cluster-2-netcore-webapp --size=g2.xsmall --nodes=1 --wait

# print kube config for the created cluster
civo k8s config Cluster-2-netcore-webapp
# apiVersion: v1
# clusters:
# - cluster:
#   name: cluster-1-just-dashboard

# save (or merge) the config into your kubeconfig
civo k8s config Cluster-2-netcore-webapp --save
# Saved config to ~/.kube/config

# print nodes and apps in your cluster
civo k8s show Cluster-2-netcore-webapp

Now with the cluster running you can just repeat what you did locally in the previous blog.
You deploy the website With the yaml with either create or apply:

# deploy image to k8s
kubectl create -f k8s-deploy-dev.yml
# deployment.apps/frontend2 created
# service/frontend2 created

# print
kubectl get services | grep frontend2
# NAME         TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
# frontend2    LoadBalancer   10.106.254.38   <pending>     5000:30300/TCP   53s

# Now test if you can reach it on
start https://www.civo.com/account/kubernetes/18779094-3e4e-4db5-85d4-6294c5eeeeee:5000 
# remove service
kubectl delete service frontend2
# service "frontend2" deleted

# remove replicaset, pod and deployment
kubectl delete deployment frontend2
# deployment.apps "frontend2" deleted
# stop the k8s cluster
docker stop Cluster-2-netcore-webapp

And finally - tear down and stop costs:

# Delete cluster
civo kubernetes remove Cluster-2-netcore-webapp
# The Kubernetes cluster called Cluster-2-netcore-webapp with ID 18779094-3e4e-4db5-85d4-6294c5eeeeee was deleted

Links

The End