<p>Consider that I have built a <strong>complex Kubernetes deployment/workload</strong> consisting of deployments, stateful sets, services, operators, CRDs with specific configuration etc…  The workload/deployment was created by  individual commands (kubectl create, helm install…)…</p>
<p>1-) Is there a way to <strong>dynamically (not manually)</strong> generate a script or a special file that describes the deployment and that could be used to redeploy/reinstall my deployment without going into each command one by one again.</p>
<p>2-) Is there a <strong>domain specific language (DSL)</strong> or something similar through which one can describe a Kubernetes deployment independently from the final target kubernetes cluster target,  whether GKE, AWS, Azure, or on premises … kind of write once deploy anywhere…</p>
<p>Thanks.</p>

Mazen Ezzeddine
<p>I think Kustomize and Helm are your best bet. We can write the helm chart as a template and decide which template to use with Go-Templating and conditions.</p>
<p>For example, look at the below configuration file which has a few conditions.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.appName }}
  namespace: {{ .Values.namespace }}
spec:
  selector:
    matchLabels:
      app: {{ .Values.appName }}
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
      annotations:
      labels:
        app: {{ .Values.appName }}
    spec:
      containers:
      - name: {{ .Values.appName }}
        image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        {{- if .Values.hasSecretVolume }}
        volumeMounts:
        - name: {{ .Values.appName }}-volume-sec
          mountPath: {{ .Values.secretVolumeMountPath }}
        {{- end}}
        {{- if or .Values.env.configMap .Values.env.secrets }}
        envFrom:
        {{- if .Values.env.configMap }}
        - configMapRef:
            name: {{ .Values.appName }}-env-configmap
        {{- end }}
        {{- if .Values.env.secrets }}
        - secretRef:
            name: {{ .Values.appName }}-env-secret
        {{- end }}
        {{- end }}
        ports:
        - containerPort: {{ .Values.containerPort }}
          protocol: TCP
{{- if .Values.railsContainerHealthChecks}}
{{ toYaml .Values.railsContainerHealthChecks | indent 8 }}
{{- end}}
      {{- if .Values.hasSecretVolume }}
      volumes:
      - name: {{ .Values.appName }}-volume-sec
        secret:
          secretName: {{ .Values.appName }}-volume-sec
      {{- end}}
      {{- if .Values.imageCredentials}}
      imagePullSecrets:
      - name: {{.Values.imageCredentials.secretName}}
      {{- end}}

</code></pre>
<p>For instance, this condition checks for Secret volume and mounts it.
<code>{{- if .Values.hasSecretVolume }}</code>
In case you are interested in <code>helm</code> and generic templating, you can refer to this medium blog: <a href="https://medium.com/srendevops/helm-generic-spring-boot-templates-c9d9800ddfee" rel="nofollow noreferrer">https://medium.com/srendevops/helm-generic-spring-boot-templates-c9d9800ddfee</a></p>
