Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Last active October 10, 2019 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruanbekker/3656fcb155855a1b3d16d643c6eff227 to your computer and use it in GitHub Desktop.
Save ruanbekker/3656fcb155855a1b3d16d643c6eff227 to your computer and use it in GitHub Desktop.
Create a Civo Kubernetes Cluster via CLI
brew install rbenv ruby-build
export LDFLAGS="-L/usr/local/opt/readline/lib"
export CPPFLAGS="-I/usr/local/opt/readline/include"
rbenv install 2.5.1
rbenv global 2.5.1
export GEM_HOME=~/.gem
export GEM_PATH=~/.gem
gem install civo_cli
cp ~/.gem/bin/civo /usr/local/bin/civo
brew install kubernetes-cli
brew install kubectx
$ civo apikey add default your-api-key
Saved the API Key your-api-key
$ civo apikey list
+---------+----------------------------------------------------+----------+
| Name    | Key                                                | Default? |
+---------+----------------------------------------------------+----------+
| default | .................................................. | <=====   |
+---------+----------------------------------------------------+----------+
$ civo kubernetes create --size=g2.xsmall "cluster-$(openssl rand -hex 5)" --nodes=3 --wait
Building new Kubernetes cluster cluster-cf30faa02a: Done
Created Kubernetes cluster cluster-cf30faa02a in 01 min 35 sec
$ civo kubernetes list
+--------------------------------------+--------------------+---------+-----------+--------+
| ID                                   | Name               | # Nodes | Size      | Status |
+--------------------------------------+--------------------+---------+-----------+--------+
| 418cc6d0-a281-46b1-a8c3-b1408d437d31 | cluster-cf30faa02a | 3       | g2.xsmall | ACTIVE |
+--------------------------------------+--------------------+---------+-----------+--------+
$ civo kubernetes show cluster-cf30faa02a
                ID : 418cc6d0-a281-46b1-a8c3-b1408d437d31
              Name : cluster-cf30faa02a
           # Nodes : 3
              Size : g2.xsmall
            Status : ACTIVE
           Version : 0.8.1
      API Endpoint : https://185.136.234.165:6443
      DNS A record : 418cc6d0-a281-46b1-a8c3-b1408d437d31.k8s.civo.com

Nodes:
+------------------+-----------------+--------+
| Name             | IP              | Status |
+------------------+-----------------+--------+
| kube-master-8406 | 185.136.234.165 | ACTIVE |
| kube-node-541e   | 185.136.234.161 | ACTIVE |
| kube-node-616f   | 185.136.234.204 | ACTIVE |
+------------------+-----------------+--------+

Installed marketplace applications:
+---------+-----------+-----------+--------------+
| Name    | Version   | Installed | Category     |
+---------+-----------+-----------+--------------+
| Traefik | (default) | Yes       | architecture |
+---------+-----------+-----------+--------------+
$ civo kubernetes config cluster-cf30faa02a --save
Merged config into ~/.kube/config
$ kubectx cluster-cf30faa02a
Switched to context "cluster-cf30faa02a".
$ kubectl get nodes
NAME               STATUS   ROLES    AGE   VERSION
kube-master-8406   Ready    master   10m   v1.14.6-k3s.1
kube-node-541e     Ready    worker   10m   v1.14.6-k3s.1
kube-node-616f     Ready    worker   10m   v1.14.6-k3s.1
$ civo applications list
+---------------------+------------+--------------+-----------------+--------------+
| Name                | Version    | Category     | Plans           | Dependencies |
+---------------------+------------+--------------+-----------------+--------------+
| cert-manager        | v0.10.0    | architecture | Not applicable  | Helm         |
| Helm                | 2.14.3     | management   | Not applicable  |              |
| Linkerd             | 2.5.0      | architecture | Not applicable  |              |
| Longhorn            | 0.5.0      | storage      | Not applicable  |              |
| Maesh               | Latest     | architecture | Not applicable  | Helm         |
| MariaDB             | 10.4.7     | database     | 5GB, 10GB, 20GB | Longhorn     |
| metrics-server      | Latest     | architecture | Not applicable  | Helm         |
| MinIO               | 2019-08-29 | storage      | 5GB, 10GB, 20GB | Longhorn     |
| MongoDB             | 4.2.0      | database     | 5GB, 10GB, 20GB | Longhorn     |
| OpenFaaS            | 0.18.0     | architecture | Not applicable  | Helm         |
| PostgreSQL          | 11.5       | database     | 5GB, 10GB, 20GB | Longhorn     |
| prometheus-operator | 0.32.0     | monitoring   | Not applicable  | Helm         |
| Redis               | 3.2        | database     | Not applicable  |              |
| Traefik             | (default)  | architecture | Not applicable  |              |
+---------------------+------------+--------------+-----------------+--------------+
$ civo applications add Longhorn --cluster cluster-cf30faa02a
Added Longhorn 0.5.0 to Kubernetes cluster cluster-cf30faa02a
$ civo kubernetes show cluster-cf30faa02a
                ID : 418cc6d0-a281-46b1-a8c3-b1408d437d31
              Name : cluster-cf30faa02a
           # Nodes : 3
              Size : g2.xsmall
            Status : ACTIVE
           Version : 0.8.1
      API Endpoint : https://185.136.234.165:6443
      DNS A record : 418cc6d0-a281-46b1-a8c3-b1408d437d31.k8s.civo.com

Nodes:
+------------------+-----------------+--------+
| Name             | IP              | Status |
+------------------+-----------------+--------+
| kube-master-8406 | 185.136.234.165 | ACTIVE |
| kube-node-541e   | 185.136.234.161 | ACTIVE |
| kube-node-616f   | 185.136.234.204 | ACTIVE |
+------------------+-----------------+--------+

Installed marketplace applications:
+----------+-----------+-----------+--------------+
| Name     | Version   | Installed | Category     |
+----------+-----------+-----------+--------------+
| Longhorn | 0.5.0     | Yes       | storage      |
| Traefik  | (default) | Yes       | architecture |
+----------+-----------+-----------+--------------+
$ civo applications add MongoDB --cluster cluster-cf30faa02a                                                                                                             1 ↵
You requested to add MongoDB but didn't select a plan. Please choose one... (5GB, 10GB, 20GB) [5GB]:
Thank you, next time you could use "MongoDB:5GB" to choose automatically
Added MongoDB 4.2.0 to Kubernetes cluster cluster-cf30faa02a
$ kubectl get pods
NAME                       READY   STATUS    RESTARTS   AGE
mongodb-595df559d9-28ccc   1/1     Running   0          18s
$ kubectl describe pods/mongodb-595df559d9-28ccc
Name:           mongodb-595df559d9-28ccc
Namespace:      default
Priority:       0
Node:           kube-master-8406/172.31.1.9
Start Time:     Thu, 10 Oct 2019 18:03:16 +0200
Labels:         app=mongodb
                pod-template-hash=595df559d9
Annotations:    <none>
Status:         Running
IP:             192.168.0.11
IPs:            <none>
Controlled By:  ReplicaSet/mongodb-595df559d9
Containers:
  mongodb:
    Container ID:   containerd://0a2a141d488222aa188dc48ec796549ebb67bf1e61c689e2b0e8cbc076827264
    Image:          mongo:4.2.0
    Image ID:       docker.io/library/mongo@sha256:7d9fe4ae781849afc70a29a0e1e4a37a2236c93a75786c576f34258e5983efbe
    Port:           27017/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Thu, 10 Oct 2019 18:03:28 +0200
    Ready:          True
    Restart Count:  0
    Environment:
      MONGO_INITDB_ROOT_USERNAME:  81W8OxPkiHu50rLDyDhxCFaf7BjdZc
      MONGO_INITDB_ROOT_PASSWORD:  sMf2yXwjb85y4PX3NM5JorctSB7QYM
    Mounts:
      /data/db from mongodb-persistent-storage (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-sbq87 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  mongodb-persistent-storage:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  mongodb-pv-claim
    ReadOnly:   false
  default-token-sbq87:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-sbq87
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason            Age                From                       Message
  ----     ------            ----               ----                       -------
  Warning  FailedScheduling  73s (x2 over 73s)  default-scheduler          pod has unbound immediate PersistentVolumeClaims (repeated 3 times)
  Normal   Scheduled         72s                default-scheduler          Successfully assigned default/mongodb-595df559d9-28ccc to kube-master-8406
  Normal   Pulling           71s                kubelet, kube-master-8406  Pulling image "mongo:4.2.0"
  Normal   Pulled            61s                kubelet, kube-master-8406  Successfully pulled image "mongo:4.2.0"
  Normal   Created           60s                kubelet, kube-master-8406  Created container mongodb
  Normal   Started           60s                kubelet, kube-master-8406  Started container mongodb
$ kubectl exec -it mongodb-595df559d9-28ccc -- mongo mongodb://81W8OxPkiHu50rLDyDhxCFaf7BjdZc:sMf2yXwjb85y4PX3NM5JorctSB7QYM@localhost:27017/
MongoDB shell version v4.2.0
connecting to: mongodb://localhost:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("8f356bc2-2092-49c1-8d93-5286d6117454") }
MongoDB server version: 4.2.0
Welcome to the MongoDB shell.
> use admin
switched to db admin
$ civo kubernetes scale cluster-cf30faa02a --nodes 4
Kubernetes cluster cluster-cf30faa02a will now have 4 nodes
$ civo kubernetes list
+--------------------------------------+--------------------+---------+-----------+-----------------+
| ID                                   | Name               | # Nodes | Size      | Status          |
+--------------------------------------+--------------------+---------+-----------+-----------------+
| 418cc6d0-a281-46b1-a8c3-b1408d437d31 | cluster-cf30faa02a | 4       | g2.xsmall | INSTANCE-CREATE |
+--------------------------------------+--------------------+---------+-----------+-----------------+
$ civo kubernetes list
+--------------------------------------+--------------------+---------+-----------+--------+
| ID                                   | Name               | # Nodes | Size      | Status |
+--------------------------------------+--------------------+---------+-----------+--------+
| 418cc6d0-a281-46b1-a8c3-b1408d437d31 | cluster-cf30faa02a | 4       | g2.xsmall | ACTIVE |
+--------------------------------------+--------------------+---------+-----------+--------+
$ kubectl get nodes
NAME               STATUS   ROLES    AGE   VERSION
kube-master-8406   Ready    master   21m   v1.14.6-k3s.1
kube-node-541e     Ready    worker   20m   v1.14.6-k3s.1
kube-node-616f     Ready    worker   20m   v1.14.6-k3s.1
kube-node-c05e     Ready    worker   16s   v1.14.6-k3s.1
$ civo kubernetes remove cluster-cf30faa02a                                                                                                                
Removing Kubernetes cluster cluster-cf30faa02a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment