I want to be able to detect the Kubernetes distribution where the application is being deployed to so I can automatically only show Config fields that apply to the distribution. I also want to be able to only run specific preflight checks, and deploy cluster specific resources.
Replicated exposes this value via the Distribution
Static Context. As he documentation states, using this you may get one of the following values:
- microk8s
- dockerDesktop
- eks
- gke
- digitalOcean
- openShift
- kurl
- aks
- ibm
- minikube
- rke2
- k3s
Below is an example of using this to display a label when the application is being deployed on GKE
apiVersion: kots.io/v1beta1
kind: Config
metadata:
name: example-config
spec:
groups:
- name: example_settings
title: My Example Config
description: Configuration to serve as an example for creating your own. See [https://kots.io/reference/v1beta1/config/](https://kots.io/reference/v1beta1/config/) for configuration docs. In this case, we provide example fields for configuring an Ingress object.
items:
- name: gke-description
type: label
title: "You are Deploying to GKE"
when: 'repl{{ eq Distribution "gke" }}'
- name: kurl-description
type: label
title: "You are Deploying to kURL"
when: 'repl{{ eq Distribution "kurl" }}'
- name: eks-description
type: label
title: "You are Deploying to EKS"
when: 'repl{{ eq Distribution "eks" }}'
When Deploying to a GKE Cluster, only the correct label is displayed:
You could also use this to determine which workload to deploy. For example, you may want to deploy different ingress based on the cloud provider.
Here is an example of a YAML that would be deployed only if the application is being deployed to GKE:
apiVersion: apps/v1
kind: Deployment
metadata:
name: gke-nginx
labels:
app: example
component: nginx
annotations:
kots.io/when: 'repl{{ eq Distribution "gke"}}'
spec:
selector:
matchLabels:
app: example
component: nginx
template:
metadata:
labels:
app: example
component: nginx
spec:
containers:
- name: nginx
image: nginx
envFrom:
- configMapRef:
name: example-configmap
resources:
limits:
memory: '256Mi'
cpu: '500m'
requests:
memory: '32Mi'
cpu: '100m'
In this case you would have a YAML definition for each cloud provider.
For Preflight Checks and Support Bundles, use the exclude
shared property . In this case, we need to test for the opposite, so you could try templating like:
exclude: '{{repl not (eq Distribution "gke") }}'
The above line would ensure that the collector
or analyzer
would only run when the Distribution is āgkeā.
For an AWS only collector
or analyzer
, it would look like this:
exclude: '{{repl not (eq Distribution "aws") }}'
TIP
If you want to see what the actual value of the āDistributionā Static Context, add a Static Data Collector like this one:
- data:
name: static/dist.txt
data: '{{repl Distribution}}'