Kubernetes: init container spec in yaml format

6/28/2018

Currently, I'm writting my init container specs inside:

metadata:
  annotations:
    pod.beta.kubernetes.io/init-containers: '[      {        "name": "sdf",        "image": "sdf"      ...

So, it forces me to write init container specs in json format.

My question is: Is there any way to write init-container specs without using this way?

-- Jordi
kubernetes

2 Answers

6/28/2018

Since 1.6, u are possible to write it in yaml way. Here is an example that we used to build up the galera cluster.

spec:
  serviceName: "galera"
  replicas: 3
  template:
    metadata:
      labels:
        app: mysql
    spec:
      initContainers:
      - name: install
        image: gcr.io/google_containers/galera-install:0.1
        imagePullPolicy: Always
        volumeMounts:
        - name: data
          mountPath: /var/lib/mysql
        - name: config
          mountPath: /etc/mysql/conf.d
      - name: bootstrap
        image: debian:jessie
        command:
        - "hello world"
        env:
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
        volumeMounts:
        - name: workdir
          mountPath: "/hello"
      containers:
      - name: mysql
        xxxxxx
-- Tim
Source: StackOverflow

6/28/2018

From Kubernetes 1.6 on there's a new syntax available. Same format as for normal pod spec, just use initContainers instead.

-- Michael Hausenblas
Source: StackOverflow