notes/articles/3. Prepare k8s cluster.md/Preparing k8s cluster for real use.md
Allen Languor 71f4cd0462 articles
2021-06-04 06:03:46 +03:00

2.6 KiB

Preparing k8s cluster for real use

After deployng a cluster and adding an admin user you may be confused what to do next. When I started learning how to use k8s I was confused, because I couln't undestand how to make anythin work.

There are several components that you may want to install in you cluster. I will tell you about my setup.

  1. Monitoring
  • Prometheus
  • Grafana
  1. Network
  • Istio
  • MetalLB
  1. Storage Provisioner
  • Rook
  1. Deployment tools
  • Keel

There are many people that will say that I shouldn't stora data inside a cluster. But I will try to explain why I'm doing it. To install most of them you can use helm charts. But when you've got a lot of helm package inside your cluster, i suppose, you'd like to have installation configured as code. So I will show how to use Github Actions to deploy charts.

Monitoring

I'm using this helm chart: https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack

It will install Prometheus, grafana and Alert-manager. This is gonna be the first packages that I'm gonna install. As you can see in README.md you can simply do

$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
$ helm repo update
$ helm install prometheus prometheus-community/kube-prometheus-stack

But when you've got several clusters or if one day your kube will fall and you will be trying to install all you packages from cli in the brand-new cluster, you mau want to automate theese steps. There a many ways to do it. You can just save the list of helm packages you need, you can write a script or create an Ansible playbook or role. But I guess, that the best way to do it is to create CI/CD pipeline that will install and update packages on pushes to repo. Of course you can run Ansible playbooks or scripts in CI/CI pipes, but this time I will show how to use Githun Actions for this kind of deployment.

  1. Create a fresh repo (I won't share my repo this time because there is some kind of sensitive data)
  2. Create a /.github/workflows/ dir
  3. You can arrange files and folders here as you want. We beggining with one cluster so let the structure be simple. Let's create a file prometheus.yml
name: Prometheus
on: ['deployment']

jobs:
  deployment:
    runs-on: 'ubuntu-latest'
    steps:
    - uses: actions/checkout@v1

    - name: 'Deploy'
      uses: 'deliverybot/helm@v1'
      with:
        release: 'nginx'
        namespace: 'default'
        chart: 'app'
        token: '${{ github.token }}'
        values: |
          name: foobar
        value-files: values.yaml
      env:
        KUBECONFIG_FILE: '${{ secrets.KUBECONFIG }}'