kube-secrets-init
kube-secrets-init is a Kubernetes mutating admission webhook, that mutates any Pod that is using specially prefixed environment variables, directly or from Kubernetes as Secret or ConfigMap.
About this chart
kube-secrets-init
kube-secrets-init is a Kubernetes mutating admission webhook, that mutates any Pod that is using specially prefixed environment variables, directly or from Kubernetes as Secret or ConfigMap.
Homepage: https://github.com/doitintl/kube-secrets-init
TL;DR;
helm repo add skm https://charts.sagikazarmark.dev
helm install --generate-name --wait skm/kube-secrets-init
⚠️⚠️⚠️ Make sure to read the Operations guide before running this chart in production! ⚠️⚠️⚠️
Configuration
Certificate
Webhooks require CA and TLS certificates to secure communication between the API server and the webhook. The chart offers the following options for certificate provisioning:
Generate (default)
The default option is to let Helm generate the CA and TLS certificates during installation.
This will renew the certificates on each deployment.
certificate:
generate: true
Using cert-manager
If have cert-manager installed in your cluster, you can use it to automatically provision and inject certificates.
certificate:
useCertManager: true
generate: false
Init container image
By default the webhook uses the latest init container image (doitintl/secrets-init:latest).
It's a good practice though to use a concrete version, because a faulty update can easily bring down your workloads (like in this case):
initContainer:
image:
tag: 0.2.12
Make sure that the webhook version if compatible with the init container version.
Operations guide
Running this webhook with the default configuration can cause serious trouble, so reading the following sections before doing so is highly recommended.
Availability and disruptions
Webook disruptions can easily render clusters inoperational by preventing launching new pods leading to unplanned outages. Kubernetes offers different features to keep that from happening:
- Fine-tune resource requests and limits to help the scheduler placing pods on nodes with enough resources.
- Run multiple replicas for higher availability.
- Spread pods across failure-domains (regions, zones, nodes) for even higher availability.
- Define a pod distruption budget for voluntary disruptions.
Here is an example configuration for higher availability, but make sure to customize it to your needs before using it in production:
replicas: 3
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 50m
memory: 32Mi
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
topologyKey: kubernetes.io/hostname
labelSelector:
matchLabels:
app.kubernetes.io/name: kube-secrets-init
app.kubernetes.io/instance: kube-secrets-init
podDisruptionBudget:
enabled: true
minAvailable: 2
You can further reduce the blast-radius of involuntary disruptions by configuring namespaceSelector and/or objectSelector
to limit the webhooks to the required namespaces/workloads.
Read more about dealing with disruptions in the Kubernetes documentation.
Scope of mutated resources
By default, the webhook mutates every pod in the cluster. While this may not sound scary at first, it can actually bring down your entire cluster (even with the default configuration) if a mutation fails.
The following sections describe how to limit the scope of mutations.
Default exclusions
As mentioned above, the webhook mutates every pod in the cluster, but there are a couple builtin exclusions:
- Pods in namespaces labeled with
kube-secrets-init.doit-intl.com/disable-mutation=true - Pods in namespaces labeled with
name=RELEASE_NAMESPACE(Helm release namespace) - Pods labeled with
kube-secrets-init.doit-intl.com/disable-mutation=true - Pods labeled with
kube-secrets-init.doit-intl.com/mutate=skip(legacy)
Although the webhook pod is tagged with kube-secrets-init.doit-intl.com/disable-mutation=true,
you can label the entire namespace where the chart is installed if you want:
kubectl create namespace kube-secrets-init
kubectl label namespace kube-secrets-init name=kube-secrets-init
Tip: It's always a good practice to label namespaces with their own name to make namespace selection easier.
⚠️⚠️⚠️ kube-system namespace ⚠️⚠️⚠️
Unwanted mutations in the kube-system namespace can cause serious trouble,
so it's a good idea to exclude it from mutations to avoid accidental cluster outages caused by failed mutations.
(Even if mutations don't fail generally, a single failure can easily cause a ripple effect with catastrophic consequences.)
The default chart configuration excludes namespaces labeled with name=kube-system.
You can easily label the kube-system namespace with its own name (if it isn't already):
kubectl label namespace kube-system name=kube-system
Keep in mind that if you provide your own namespaceSelector the default gets overridden.
Read on to learn more about custom selectors and other options to avoid mutations in the kube-system.
Custom selectors
Mutating webhooks can be configured to mutate various resources matching various rules.
This webhook only mutates pod resources, but there are a couple options that this chart allows you to modify:
Namespace selectors can limit mutations for objects found in namespaces matching the selectors.
For example, the default namespace selector excludes namespaces labeled with name=kube-system (see the kube-system section above):
namespaceSelector:
matchExpressions:
- key: name
operator: NotIn
values:
- kube-system
A simplified syntax if you want to include matches instead of excluding them:
namespaceSelector:
matchLabels:
kube-secrets-init.doit-intl.com/enable-mutation: "true"
Object selectors are similar to namespace selectors, except they are evaluated against the objects themselves.
It is important to understand that all conditions (namespace and object selectors, matchExpressions and matchLabels)
must all be satisfied at the same time in order to match. As a result, there are several strategies for limiting mutations:
An exclude-only approach only uses matchExpressions and operators, like NotIn (see the examples above).
This way you can exclude anything you don't want to mutate, everything else will be mutated.
While this is a good default approach, misconfiguration (eg. forgeting to label a namespace)
can easily lead to unwanted outages if a mutation fails.
An include approach ensures that only those objects are mutated that you specifically label. This is a safer approach, but requires you to label more resources.
Choose the approach that fits your use case best. You can even combine the two if you want to (for example label namespaces you want mutations to happen in, but label some objects within those namespaces that you don't want to mutate).
See the documentation
to read more about labels, selectors, matchExpressions and matchLabels.
Ignoring failures
The previous sections mentioned failing mutations and their consequences, particularly when pods in the kube-system namespace are mutated.
Mutations can fail for various reasons from bugs to the webhook service not being available (see Availability and disruptions).
If you find that mutations fail a lot, even when the webhook runs in a highly available manner,
you don't have a lot of options: you either accept the fact that mutations will sometimes fail (keeping pods from start),
or you decide to ignore these failures by changing the default failure policy
to Ignore.
This is useful if a running, but non-functional application is still better than nothing (for example in case of a web application).
About GKE Private Clusters
When Google configure the control plane for private clusters, they automatically configure VPC peering between your Kubernetes cluster’s network in a separate Google managed project.
The auto-generated rules only open ports 10250 and 443 between masters and nodes. This means that to use the webhook component with a GKE private cluster, you must configure an additional firewall rule to allow your masters CIDR to access your webhook pod using the port 8443.
You can read more information on how to add firewall rules for the GKE control plane nodes in the GKE docs.
Values
| Key | Type | Default | Description |
|---|---|---|---|
| replicaCount | int | 1 | Number of replicas (pods) to launch. |
| image.repository | string | "ghcr.io/doitintl/kube-secrets-init" | Name of the image repository to pull the container image from. |
| image.pullPolicy | string | "IfNotPresent" | Image pull policy for updating already existing images on a node. |
| image.tag | string | "" | Image tag override for the default value (chart appVersion). |
| logLevel | string | "info" | Log-level for the kube-secrets-init container. Valid values are "info", "debug", "warning", "error", "fatal", "panic". |
| imagePullSecrets | list | [] | Reference to one or more secrets to be used when pulling images (from private registries). |
| nameOverride | string | "" | A name in place of the chart name for app: labels. |
| fullnameOverride | string | "" | A name to substitute for the full names of resources. |
| provider | string | "" | One of the supported secret providers: - google (Google Cloud Secrets Manager) - aws (AWS Secrets Manager and SSM Parameter Store) |
| defaultImagePullSecret.name | string | "" | Fallback secret name to use when no image pull secret is found. |
| defaultImagePullSecret.namespace | string | "" | Namespace of the fallback secret name. |
| initContainer.image.repository | string | ghcr.io/doitintl/secrets-init (from CLI defaults) | Name of the image repository to pull the init container image from. |
| initContainer.image.pullPolicy | string | IfNotPresent (from CLI defaults) | Image pull policy for updating already existing images on a node. |
| initContainer.image.tag | string | latest (from CLI defaults) | Image tag for the init container. Note: it is strongly recommended to change the image tag to avoid issues like this. |
| certificate.useCertManager | bool | false | Use jetstack/cert-manager for creating the necessary certificates. This is usually preferred as cert-manager automatically renews certificates. Mutually exclusive with generate. |
| certificate.generate | bool | true | Generate the necessary certificates during chart install. Mutually exclusive with useCertManager. |
| certificate.secretName | string | "" | The name of the secret to use. If not set and useCertManager or generate is true, a name is generated using the fullname template. |
| serviceAccount.create | bool | true | Enable service account creation. |
| serviceAccount.annotations | object | {} | Annotations to be added to the service account. |
| serviceAccount.name | string | "" | The name of the service account to use. If not set and create is true, a name is generated using the fullname template. |
| rbac.create | bool | true | Enable the creation of RBAC resources. If disabled, the operator (ie. the person installing the chart) is responsible for creating the necessary resources based on the templates. |
| podAnnotations | object | {} | Annotations to be added to pods. |
| priorityClassName | string | "" | Specify a priority class name to set pod priority. |
| podDisruptionBudget.enabled | bool | false | Enable a pod distruption budget to help dealing with disruptions. It is highly recommended for webhooks as disruptions can prevent launching new pods. |
| podDisruptionBudget.minAvailable | int/percentage | nil | Nu |
Deploy kube-secrets-init with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has kube-secrets-init 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.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartkube-secrets-init is pinned at v0.9.3 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- 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