base-cluster

by teuto.net

Helm chartv13.1.0Verified publisher

A common base for every kubernetes cluster. This chart bootstraps a cluster with the shared components every teuto.net cluster needs. It is managed via Flux and intended to be installed once, after which Flux takes over further reconciliation of the chart itself.

About this chart

A common base for every kubernetes cluster. This chart bootstraps a cluster with the shared components every teuto.net cluster needs. It is managed via Flux and intended to be installed once, after which Flux takes over further reconciliation of the chart itself.

Homepage: https://teuto.net

Maintainers

NameEmailUrl
cwrau[email protected]
marvinWolff[email protected]
tasches[email protected]

Cluster bootstrap

The .x.x part of the versions can be left as is, helm uses that as a range. If you choose to set a fix version, you have to take care of the updates yourself.

# always be git 😁
git init

# create empty cluster HelmRelease;
flux create helmrelease --export base-cluster -n flux-system --source HelmRepository/teuto-net.flux-system --chart base-cluster --chart-version 13.x.x > cluster.yaml

# maybe use the following name for your cluster;
kubectl get node -o jsonpath='{.items[0].metadata.annotations.cluster\.x-k8s\.io/cluster-name}'

# configure according to your needs, at least `.global.clusterName` is needed
# additionally, you should add your git repo to `.flux.gitRepositories`, see [the documentation](https://github.com/teutonet/teutonet-helm-charts/tree/main/charts/base-cluster#81--property-base-cluster-configuration--flux--gitrepositories)
# make sure to use the correct url format, see [the documentation](https://github.com/teutonet/teutonet-helm-charts/tree/main/charts/base-cluster#81112-property-base-cluster-configuration--flux--gitrepositories--additionalproperties--allof--item-0--oneof--item-1)
vi cluster.yaml

# create HelmRelease for flux to manage itself
kubectl create namespace flux-system --dry-run=client -o yaml > flux.yaml
flux create source helm --url https://fluxcd-community.github.io/helm-charts flux -n flux-system --export >> flux.yaml
flux create helmrelease --export --crds CreateReplace flux -n flux-system --source HelmRepository/flux.flux-system --chart flux2 --chart-version 2.x.x >> flux.yaml

# add, commit and push resources
git add cluster.yaml flux.yaml
git commit cluster.yaml flux.yaml
git push

# after this you should be on the KUBECONFIG for the cluster
# we explicitly do not use `flux bootstrap` or `flux install` as this creates kustomization stuff and installs flux manually
kubectl apply --server-side -f flux.yaml # ignore the errors about missing CRDs
helm install -n flux-system flux flux2 --repo https://fluxcd-community.github.io/helm-charts --version 2.x.x --atomic

# manual initial installation of the chart, afterwards the chart takes over
# after the installation finished, follow the on-screen instructions to configure your flux, distribute KUBECONFIGs, ...
helm install -n flux-system base-cluster oci://ghcr.io/teutonet/teutonet-helm-charts/base-cluster --version 13.x.x --values <(cat cluster.yaml | yq -y .spec.values)

# you can use this command to get the instructions again
# e.g. when adding users, gitRepositories, ...
helm -n flux-system get notes base-cluster

⚠️ Due to various reasons, it's not possible to cleanly uninstall this via a normal kubectl delete, helm uninstall or via flux deletion. See the corresponding issue

Cluster components

Component backup

velero takes care of backing up your PVCs.

Component cert-manager

cert-manager takes care of creating SSL certificates for your Ingresses (and other needs)

  1. set .certManager.email to your email for the Let's Encrypt account to enable certificates

To create wildcard certificates, you need to enable a DNS Provider

Then you can just create a Certificate resource.

Component descheduler

The descheduler runs periodically and tries to average the load across the nodes by deleting pods on fuller nodes so the kube-scheduler can, hopefully, schedule them on nodes with more space.

Additionally, the descheduler also tries to reconcile topologySpreadConstraints and affinities.

If the cluster is semi underspecced or the individual applications have imperfect resource requests, the descheduler might lead to period restarting of random pods.

In that case you should disable the descheduler.

Pods that run a one-off job without a controller to resume it (e.g. CI runners) are lost when evicted mid-job. List their namespaces in descheduler.excludedNamespaces to keep the descheduler from evicting them when rebalancing node utilization.

Component dns

The external-dns creates, updates, deletes and syncs DNS records for your Ingresses.

  1. set .dns.provider.<provider> to your implementation:
    • cloudflare: .dns.provider.cloudflare.apiToken

If you need a different provider than cloudflare, please open a ticket for one of the supported ones which is also supported by cert-manager

Component ingress

The chart supports three ingress controllers:

  1. nginx ingress-controller

    • Works with IngressClassName: nginx or if none is defined
    • Provides built-in metrics and tracing support
  2. traefik

    • Works with IngressClassName: ingress-controller or if none is defined
    • Provides built-in metrics and tracing support
    • Also supports Gateway API
  3. envoy (default)

    • Gateway API-based, deployed via Envoy Gateway
    • Full feature parity with traefik for IP handling, resources and proxy-protocol
    • Tracing requires the OTLP endpoint to be auto-discovered (the default): envoy wires up tracing via a Gateway API-style backend reference to the discovered collector Service, whereas traefik/nginx accept any host:port. Setting global.telemetry.otlp.endpoint explicitly is not yet supported with envoy and fails the template render
    • customDomain on the grafana/prometheus/alertmanager ingresses is served via a per-component Gateway API ListenerSet attached to the shared Gateway, each with its own cert-manager-issued certificate; requires the cluster's Gateway API CRDs to include ListenerSet (Gateway API >= v1.5)
    • Migrates cleanly from traefik: same ingress namespace, no namespace deletion, and the existing Service - including its LoadBalancer IP - keeps being used as-is (reuse comes from envoy targeting the same Service name/namespace as traefik, not from the helm.sh/resource-policy: keep annotation, which only stops Helm from deleting the Service when the traefik HelmRelease is removed)
    • Ingress resources are not served, so a ValidatingAdmissionPolicy denies creating and updating them (deleting stays allowed) to fail early instead of silently doing nothing (on kubernetes >= 1.30). Opt out via ingress.blockIngressResource: false
    • Cannot be adopted directly from nginx - there is no dual-mode path for that combination, migrate to traefik first, then to envoy

TLS

  1. add kubernetes.io/tls-acme: "true" to your Ingress's annotations
    • additionally, although not advised unless you know what you're doing, you can explicitly choose the Issuer by using these annotations:
      • cert-manager.io/cluster-issuer: letsencrypt-staging
      • cert-manager.io/cluster-issuer: letsencrypt-production

IP Address

If you want to make sure that, in the event of a catastrophic failure, you keep the same IP address, you should roll this out, get the assigned IP (kubectl -n ingress-nginx get svc ingress-nginx-controller -o jsonpath='{.status.loadBalancer.ingress}' for nginx or kubectl -n ingress get svc ingress-controller -o jsonpath='{.status.loadBalancer.ingress}' for traefik or envoy) and set .ingress.IP=<ip> in the values. This makes sure the IP is kept in your project (may incur cost!), which means you can reuse it later or after recovery.

Component flux

Flux is used to deploy resources to your cluster and to keep them in sync.

Flux can also auto-update images and HelmReleases.

You can create any number of gitRepository connections, with SSH(recommended) or https checkout, with or without SOPS, ... .

Component kyverno

You can optionally enable kyverno, which is a policy system, allowing you to specify in-depth policies to prevent or force certain things in your cluster.

Component monitoring

Sub-Component prometheus

Prometheus takes care of scraping metrics and alerting.

Sub-Component grafana

Grafana is used to create dashboards to visualize your metrics and the health of your cluster and applications.

Sub-Component loki

Loki collects logs from across the cluster and allows to have a centralized, non-CLI, view of the logs and to create alerting based on them.

Sub-Component metrics-server

Metrics Server implements the kubernetes Metrics API to allow for Horizontal Autoscaling, Vertical Autoscaling and to allow kubectl top and tools like k9s to show resource usage for your pods and nodes.

Sub-Component securityScanning

The included trivy scans the running workload in your cluster for CVEs and creates Custom Resources to present the results.

Sub-Component tracing

The included OpenTelemetry Collector collects traces via otlp-grpc on every node via the open-telemetry-collector-opentelemetry-collector.monitoring service. These traces are then sent to Grafana Tempo, which is included as a datasource in Grafana by default.

Usage Example

In your deployment/statefulset/daemonset/... add the following config;

spec:
  template:
    spec:
      containers:
        - env:
            - name: OTEL_HOST <- change this to your framework's environment variable
              value: open-telemetry-collector-opentelemetry-collector.monitoring
            - name: OTEL_PORT
              value: "4317"

The supported protocols are;

  • jaeger
    • grpc: 14250
    • thrift_http: 14268
    • thrift_compact: 6831
  • otlp
    • grpc: 4317
    • http: 4318
  • zipkin: 9411

Component storage

The included NFS Ganesha server and external provisioner provides rudimentary support for RWM volumes if needed.

⚠️ This is not highly available, and the software itself does not support it. You should only use this if there is no other choice and make sure you're cloud provider knows about this, because a node rotation will result in a downtime for all attached applications!

Component rbac

This chart gives you the ability to create roles, roleBindings and namespaces with a, hopefully easy to understand, DSL.

All accounts and groups authenticate via OIDC; no ServiceAccounts or tokens are created for them, as static service account tokens are a security risk. Accounts with an @ in their name (an email) are bound as that user, accounts without one are bound using their OIDC identity name. rbac.groups works the same way as rbac.accounts, but binds the name as an OIDC group instead of a user; a name cannot be used as both an account and a group.

Note that your OIDC provider may prefix or suffix the username/group claims (e.g. oidc:[email protected] instead of [email protected]) before the apiserver sees them, so the account/group name you bind against might need to include that. If it's not working, ask your kubernetes hoster or check the --oidc-username-claim/--oidc-username-prefix/--oidc-groups-claim/--oidc-groups-prefix flags on your apiserver.

Miscellaneous

  • You can create HelmRepositoys; .global.helmRepositories.<name>.url=<url>
  • You can create cluster-wide certificates; .global.certificates.<name>.dnsNames=[<domain>]
  • You can create namespaces; .global.namespaces.<name>={}
  • You can create cluster-wide imageCredentials; .global.imageCredentials.<name>.{host,username,password}

Source Code

Requirements

Kubernetes: >=1.27.0-0

RepositoryNameVersion
oci://ghcr.io/teutonet/

Deploy base-cluster with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has base-cluster on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartbase-cluster is pinned at v13.1.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply