In this article, we will install the Kubernetes Package Manager “helm” and deploy a Statefulset on to a Kubernetes cluster. First, we will do it as a helm chart and then also the traditional way of using the “kubectl apply” command.

This is the continuation of the previous article on setting up the k8s cluster using “kubeadm” and the changes that are needed for the cluster to support GCP Dynamic storage. When the Cluster is tweaked for Storage we will then install the Kubernetes Open Source Package Manager “helm” and subsequently a Statefulset workload on to a GCP Cloud using dynamic provisioning.

For the Statefulset to function make the following 4 changes

  1. kube-api-server.yaml enable flag: We need to add the “DefaultStorageClass” to enable the admission-plugin as show below
$ sudo vi /etc/kubernetes/manifests/kube-api-server.yaml
  .
  .
  .
  - --authorization-mode=Node,RBAC
    - --client-ca-file=/etc/kubernetes/pki/ca.crt
    - --enable-admission-plugins=NodeRestriction,DefaultStorageClass
    - --enable-bootstrap-token-auth=true
  .
  .

2. kube-controller-manager.yaml : Add the cloud-provider flag to the existing definitions . In this case it is “gce” (Google Cloud)

$ sudo vi /etc/kubernetes/manifests/kube-controller-manager.yaml
  .
  .
  .
  - --service-cluster-ip-range=10.96.0.0/12
    - --use-service-account-credentials=true
    - --cloud-provider=gce
    image: k8s.gcr.io/kube-controller-manager:v1.18.2
  .
  .

3. Create a cloud-config file: Go to your “/etc/kubernetes” folder and create a file with your GCP project id

$ vi /etc/kubernetes/cloud-config
  [Global]
  project-id = rosy-cache-200605

Replace the “project-id” to your’s on the GCP cloud

4. “kubelet” flag option: Also make the following changes to the Kubelet . This needs to be repeated for all the nodes including the master and then restart the kubelet

$ sudo vi /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
  .
  [Service]
  Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-   kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --cloud-  provider=gce --cloud-config=/etc/kubernetes/cloud-config --kubeconfig=/etc/kubernetes/kubelet.conf"

We have added the “cloud-provider” as well as the “cloud-config” option

To restart the kubelet service

$ sudo systemctl restart kubelet

With the above changes, you are instructing the k8s cluster to make use of CloudAPI, in this case GCP to provision your dynamic storage.

Make sure your k8s cluster is Up and Running after the above changes.

To install helm3: If you already have helm installed skip to the next section.

$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
$ chmod 700 ./get_helm.sh
$ ./get_helm.sh
  Downloading https://get.helm.sh/helm-v3.2.1-linux-amd64.tar.gz
  Preparing to install helm into /usr/local/bin
  helm installed into /usr/local/bin/helm

To check if the install went thru fine…

$ helm version
  version.BuildInfo{Version:"v3.2.1",     GitCommit:"fe51cd1e31e6a202cba7dead9552a6d418ded79a", GitTreeState:"clean", GoVersion:"go1.13.10"}

To instantiate the helm boilerplate let’s do “create”

$ helm create statefulset
  Creating statefulset

If you look into the folder structure it is similar to this

$ cd statefulset ; ls
values.yaml
Chart.yaml
charts
templates

The “templates” folder is where we have all the resource definitions in YAML which Helm applies when we package and install the project.

Adding custom templates for Statefulset workloads in Helm

Let’s add the following YAML definitions in the templates folder

  • **ssd-sc.yaml **for creating the storage class
  • statefulset.yaml for the statefulset deployment
  • statefulset-service.yaml for accessing the services

The yaml definitions are as shown below

#distributed-systems #helm #cloud-computing #storage #kubernetes

Dynamic provisioning of Storage on a GCP Kubernetes cluster using Helm Charts
1.65 GEEK