mariadb sample, this creates config, pvc and deployment with initcontainer.

apiVersion: v1
data:
  my.cnf: ""
kind: ConfigMap
metadata:
  name: config-mariadb
  namespace: wow
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    io.kompose.service: db-claim0
  name: db-claim0
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 4Gi
status: {}
---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  labels:
    io.kompose.service: mariadb
  name: mariadb
  namespace: wow
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: mariadb
  strategy:
    rollingUpdate:
      maxSurge: 3
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        io.kompose.service: mariadb
    spec:
      containers:
      - env:
        - name: MARIADB_ROOT_PASSWORD
          value: xxxxx
        image: bitnami/mariadb:10.2.14
        imagePullPolicy: IfNotPresent
        name: cmangos-classic-db
        ports:
        - containerPort: 3306
          name: mysql
          protocol: TCP
        livenessProbe:
          exec:
            command:
            - mysqladmin
            - ping
          failureThreshold: 3
          initialDelaySeconds: 30
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
        readinessProbe:
          exec:
            command:
            - mysqladmin
            - ping
          failureThreshold: 3
          initialDelaySeconds: 5
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        resources:
          requests:
            cpu: 250m
            memory: 256Mi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /bitnami/mariadb
          name: db-claim0
      dnsPolicy: ClusterFirst
      initContainers:
      - command:
        - sh
        - -c
        - mkdir -p /bitnami/mariadb/conf && cp /bitnami/mariadb_config/my.cnf /bitnami/mariadb/conf/my_custom.cnf
        image: busybox
        imagePullPolicy: IfNotPresent
        name: copy-custom-config
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /bitnami/mariadb_config
          name: config
        - mountPath: /bitnami/mariadb
          name: db-claim0
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext:
        fsGroup: 1001
        runAsUser: 1001
      terminationGracePeriodSeconds: 5
      volumes:
      - name: db-claim0
        persistentVolumeClaim:
          claimName: db-claim0
      - configMap:
          defaultMode: 420
          name: config-mariadb
        name: config

A example of init container and how to remap its value

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "2"
  creationTimestamp: 2018-07-13T17:54:46Z
  generation: 3
  labels:
    app: unicorn
    chart: unicorn-0.2.3
    heritage: Tiller
    release: gitlab
  name: gitlab-unicorn
  namespace: gitlab
spec:
  progressDeadlineSeconds: 600
  replicas: 2
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: unicorn
      release: gitlab
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      annotations:
        checksum/config: 636f79b0809754ed70bdbf77bf840fc2cc37d6387dfc5cac349192e9fbca9157
        prometheus.io/path: /-/metrics
        prometheus.io/port: "8080"
        prometheus.io/scrape: "true"
      labels:
        app: unicorn
        release: gitlab
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - podAffinityTerm:
              labelSelector:
                matchLabels:
                  app: unicorn
                  release: gitlab
              topologyKey: kubernetes.io/hostname
            weight: 1
      containers:
      - env:
        - name: GITALY_FEATURE_DEFAULT_ON
          value: "1"
        - name: GITLAB_WORKHORSE_EXTRA_ARGS
        - name: CONFIG_TEMPLATE_DIRECTORY
          value: /var/opt/gitlab/templates
        - name: CONFIG_DIRECTORY
          value: /var/opt/gitlab/config/gitlab/
        - name: prometheus_multiproc_dir
          value: /metrics
        image: registry.gitlab.com/gitlab-org/build/cng/gitlab-unicorn-ee:latest
        imagePullPolicy: Always
        livenessProbe:
          exec:
            command:
            - /scripts/healthcheck
          failureThreshold: 3
          initialDelaySeconds: 20
          periodSeconds: 60
          successThreshold: 1
          timeoutSeconds: 30
        name: unicorn
        ports:
        - containerPort: 8080
          name: unicorn
          protocol: TCP
        - containerPort: 8181
          name: workhorse
          protocol: TCP
        readinessProbe:
          exec:
            command:
            - /scripts/healthcheck
          failureThreshold: 3
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        resources:
          requests:
            cpu: 200m
            memory: 2G
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /metrics
          name: unicorn-metrics
        - mountPath: /var/opt/gitlab/templates
          name: unicorn-config
        - mountPath: /etc/gitlab
          name: unicorn-secrets
          readOnly: true
        - mountPath: /home/git/gitlab/config/secrets.yml
          name: unicorn-secrets
          subPath: rails-secrets/secrets.yml
        - mountPath: /home/git/gitlab/config/initializers/smtp_settings.rb
          name: unicorn-config
          subPath: smtp_settings.rb
        - mountPath: /home/git/gitlab/INSTALLATION_TYPE
          name: unicorn-config
          subPath: installation_type
      dnsPolicy: ClusterFirst
      initContainers:
      - command:
        - sh
        - /config/configure
        image: busybox:latest
        imagePullPolicy: Always
        name: configure
        resources:
          requests:
            cpu: 50m
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /config
          name: unicorn-config
          readOnly: true
        - mountPath: /init-config
          name: init-unicorn-secrets
          readOnly: true
        - mountPath: /init-secrets
          name: unicorn-secrets
      - args:
        - /scripts/wait-for-deps
        env:
        - name: GITALY_FEATURE_DEFAULT_ON
          value: "1"
        - name: CONFIG_TEMPLATE_DIRECTORY
          value: /var/opt/gitlab/templates
        - name: CONFIG_DIRECTORY
          value: /var/opt/gitlab/config/gitlab/
        - name: WORKHORSE_ARCHIVE_CACHE_DISABLED
          value: "1"
        image: registry.gitlab.com/gitlab-org/build/cng/gitlab-unicorn-ee:latest
        imagePullPolicy: Always
        name: dependencies
        resources:
          requests:
            cpu: 50m
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /var/opt/gitlab/templates
          name: unicorn-config
        - mountPath: /etc/gitlab
          name: unicorn-secrets
          readOnly: true
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext:
        fsGroup: 1000
        runAsUser: 1000
      terminationGracePeriodSeconds: 30
      volumes:
      - emptyDir:
          medium: Memory
        name: unicorn-metrics
      - configMap:
          defaultMode: 420
          name: gitlab-unicorn
        name: unicorn-config
      - name: init-unicorn-secrets
        projected:
          defaultMode: 256
          sources:
          - secret:
              items:
              - key: secrets.yml
                path: rails-secrets/secrets.yml
              name: gitlab-rails-secret
          - secret:
              items:
              - key: secret
                path: shell/.gitlab_shell_secret
              name: gitlab-gitlab-shell-secret
          - secret:
              items:
              - key: token
                path: gitaly/gitaly_token
              name: gitlab-gitaly-secret
          - secret:
              items:
              - key: secret
                path: redis/password
              name: gitlab-redis-secret
          - secret:
              items:
              - key: postgres-password
                path: postgres/psql-password
              name: gitlab-postgresql-password
          - secret:
              items:
              - key: tls.key
                path: registry/gitlab-registry.key
              name: gitlab-registry-tls
          - secret:
              items:
              - key: accesskey
                path: minio/accesskey
              - key: secretkey
                path: minio/secretkey
              name: gitlab-minio-secret
      - emptyDir:
          medium: Memory
        name: unicorn-secrets

Make conditional pod start order

A lot of use cases are that we need to make some pod only start after specific pods are ready, take database postgres as an example:

kind: Deployment
apiVersion: apps/v1
metadata:
  name: webapp
  namespace: app
spec:
  selector:
    matchLabels:
      app: webapp
  template:
    metadata:
      labels:
        app: webapp
    spec:
      initContainers:
      - name: check-db-ready
        image: postgres:11.2-alpine
        command: ["/bin/sh"]
        args: ["-c", "until pg_isready -h db -p 5432; do echo waiting for database; sleep 2; done;"]
      containers:
      ...omit

this will boot up a probe svc to monitor readiness of db first, then start real webapp container.

Search for key words and list all relevant results:

kubectl get svc -n kube-system -o json | jq -r ' .items[] | select (.spec.selector.app=="nginx-ingress") | .metadata.name '
## Output:
## default-nginx-controller-nginx-ingress-controller
## default-nginx-controller-nginx-ingress-default-backend

This example searches names for all svc which carrys selector app:nginx-ingress.