Kubernetes infrastructure as code best practice

3/4/2020

Can anyone point me to the common strategy to setup a Kubernetes cluster according to the principles of infrastructure as code and automatic deployment for different developer teams with Git repos and an undefined CI/CD platform.

Let's say I am going to use Terraform to deploy a Kubernetes cluster on a hypothetical cloud service named QKS with a commonly used service, for example Apache Airflow, for which a public helm chart is available. There are two custom services (from two independent developer groups) to deploy named "apples" and "bananas".

I am struggling with the separation of responsibilities of different code bases. Which steps in this process can best still be done manually. A lot is being written about this technology, but I cannot find any articles on this issue in particular.

-- Joost Döbken
kubernetes
kubernetes-helm

2 Answers

3/4/2020

This is my own proposal.

Have three git repositories:

  • my-infrastructure: includes the Terraform files, the Airflow Helm deployment and deployment of two namespaces included access roles to these namespaces. CICD tracks for changes and deploys them on QKS
  • apples: code base and corresponding helm template. CICD can deploy on the apples namespace only.
  • bananas: code base and corresponding helm template. CICD can deploy on the bananas namespace only. enter image description here

Notes:

-- Joost Döbken
Source: StackOverflow

3/4/2020

There is an interesting kubernetes project for this called cluster-api that lets you create, configure & manage kubernetes clusters in a declarative fashion in a way similar to how we manage different resources in kubernetes itself. It defines new resources of different kinds like Cluster, Machine

e.g. You could define a cluster like this:

apiVersion: cluster.x-k8s.io/v1alpha2
kind: Cluster
metadata:
  name: capi-quickstart
spec:
  clusterNetwork:
    pods:
      cidrBlocks: ["192.168.0.0/16"]
  infrastructureRef:
    apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
    kind: AWSCluster
    name: capi-quickstart

Of course you would need a starting / bootstrap kubernetes cluster where you will deploy this resource. This project is still in prototype stage, so use caution.

Check out the cluster-api repository on Github: https://github.com/kubernetes-sigs/cluster-api

-- Abhishek Jaisingh
Source: StackOverflow