This document guides the cloud users how to create a kubernetes cluster and deploy a simple application.

Kubernetes, also known as K8s, is an open-source system for automating deployment, scaling, and management of containerized applications. If you are not familiar with K8s, see Kubernetes Tutorial presented at a SDSC event in 2022 where you can find relevent slides. There are also some useful introduction materials provided by IBM: 1) Docker and 2) Kubernetes, and those presented by Red Hat: 1) What's a Linux container? and 2) What is Kubernetes?



Step 0. Prerequisites


# the name of the rc file will reflect your project name. In this case, the project name is 'spherex'
> source spherex-openrc.sh  # this will ask for a password. Use the same password that you use for the dashboard.
# The rc file need to be loaded before you use openstack cli tools.


# somehow, openstack cli packages from ubuntu does not work. Instead, we install them via pip command.
> sudo apt-get install python-dev python3-pip # install pip
> sudo pip install python-openstackclient python-magnumclient
# depending on what you want to do with openstack cli, you may need to install other packages. For our purpose, magnum client should be sufficient.


TEMPLATE_NAME=k8s-spherex-test20
NETWORK_NAME=spherex-network
SUBNET_NAME=spherex-subnet
KEYPAIR=spherex-gw-ubuntu01
# DNS=8.8.8.8
DNS=210.110.233.74
LABELS="ingress_controller=octavia,cinder_csi_enabled=true,auto_healing_enabled=false,auto_scaling_enabled=false,availability_zone=nova"
# LABELS="auto_healing_enabled=false,auto_scaling_enabled=false,availability_zone=nova"

openstack coe cluster template create $TEMPLATE_NAME \
                           --coe kubernetes \
                           --image fedora-core-32 \
                           --external-network public \
                           --fixed-network $NETWORK_NAME \
                           --fixed-subnet $SUBNET_NAME \
                           --network-driver calico \
                           --dns-nameserver $DNS \
                           --floating-ip-disabled \
                           --master-flavor C8M16D40 \
                           --flavor C8M16D40 \
                           --keypair $KEYPAIR \
                           --volume-driver cinder \
                           --docker-storage-driver overlay \
                           --docker-volume-size 20 \
                           --labels $LABELS

Step 1. Create a Kubernetes (k8s) cluster


Fig. 1-1 General setup tab for creating k8s from templateFig. 1-2 "size" tab


Fig. 1-3 "Network" tabFig. 1-4 "Management" tabFig. 1-5 "Advanced" tab

Fig. 1-6: resize the cluster


Step 2. Setup connection to the created k8s cluster


> source spherex-openrc.sh  # this will ask for a password. Use the same password that yo use for the dashboard.
> openstack coe cluster config YOUR-K8S-CLUSTER-NAME
# The above command will create a file named "config" under the current directory. This is basically a kube config file that you can use with kubectl command.
# You may environment variable of "KUBECONFIG" to this file, as suggested by the above command. You may instead copy this file under "~/.kube"


Now your "kubectl" command is connected to your newly created cluster.


> kubectl get nodes
NAME                                          STATUS   ROLES    AGE    VERSION
spherex-k8s-calico100-4giy6vd2vahl-master-0   Ready    master   7d2h   v1.18.2
spherex-k8s-calico100-4giy6vd2vahl-node-0     Ready    <none>   7d2h   v1.18.2
spherex-k8s-calico100-4giy6vd2vahl-node-1     Ready    <none>   7d2h   v1.18.2
spherex-k8s-calico100-4giy6vd2vahl-node-2     Ready    <none>   7d2h   v1.18.2

> kubectl get pods -n kube-system
NAME                                         READY   STATUS    RESTARTS   AGE
calico-kube-controllers-795c4545c7-rl56t     1/1     Running   0          7d2h
calico-node-4rs5j                            1/1     Running   0          7d2h
calico-node-7bj8r                            1/1     Running   0          7d2h
calico-node-8slht                            1/1     Running   0          7d2h
calico-node-rxg5s                            1/1     Running   0          7d2h
coredns-5f98bf4db7-l6cd7                     1/1     Running   0          21h
coredns-5f98bf4db7-vzhn8                     1/1     Running   0          21h
dashboard-metrics-scraper-6b4884c9d5-p87b5   1/1     Running   0          7d2h
k8s-keystone-auth-n2dkh                      1/1     Running   0          7d2h
kube-dns-autoscaler-75859754fd-fd99t         1/1     Running   0          7d2h
kubernetes-dashboard-c98496485-wl4r4         1/1     Running   0          7d2h
npd-4bw99                                    1/1     Running   0          7d2h
npd-5sg2c                                    1/1     Running   0          7d2h
npd-cg6pc                                    1/1     Running   0          7d2h
octavia-ingress-controller-0                 1/1     Running   0          7d2h
openstack-cloud-controller-manager-796tr     1/1     Running   0          7d2h
 


Step 3. Setup Storage class


apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: cinder-default
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: cinder.csi.openstack.org

> kubectl apply -f sc-cinder.yaml
> kubectl get storageclass
NAME                       PROVISIONER                RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
cinder-default (default)   cinder.csi.openstack.org   Delete          Immediate           false                  25h