k8s-bootstrap.yaml 2.03 KB
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: k8s-bootstrap-config
  namespace: kube-system
data:
  HOME: /tmp/cluster-home
  SSH_CONFIG: |
    StrictHostKeyChecking no

#-i /tmp/cluster-ssh/ssh-private-key
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: k8s-bootstrap-scripts
  namespace: kube-system
data:
  clone-start-of-day: |
    #!/bin/sh
    set -ex
    # FIXME: don't hard-code this.
    ls -alR $HOME
    git clone git@gitlab.brainfood.com:brainfood/k8s-start-of-day.git /tmp/git-storage/k8s-start-of-day
---
apiVersion: batch/v1
kind: Job
metadata:
  name: k8s-bootstrap
  namespace: kube-system
spec:
  template:
    spec:
      restartPolicy: OnFailure
      securityContext:
        runAsUser: 1234
        runAsGroup: 1234
        fsGroup: 1234

      tolerations:
      - effect: NoSchedule
        key: node-role.kubernetes.io/master

      volumes:
        - name: k8s-bootstrap-scripts
          configMap:
            name: k8s-bootstrap-scripts
            defaultMode: 0755
        - name: git-storage
          emptyDir: {}
        - name: cluster-ssh
          secret:
            secretName: cluster-ssh
            defaultMode: 0600

      initContainers:
        - name: clone-k8s-start-of-day
          image: bitnami/git
          envFrom:
            - configMapRef:
                name: k8s-bootstrap-config
          volumeMounts:
            - name: k8s-bootstrap-scripts
              mountPath: /tmp/k8s-bootstrap-scripts
            - name: cluster-ssh
              mountPath: /tmp/cluster-home/.ssh/id
              subPath: ssh-private-key
            - name: cluster-ssh
              mountPath: /tmp/cluster-home/.ssh/config
              subPath: SSH_CONFIG
            - name: git-storage
              mountPath: /tmp/git-storage
          command: ["/tmp/k8s-bootstrap-scripts/clone-start-of-day"]

      containers:
        - name: show-status
          image: bash
          command: ["bash", "-ex", "ls -al /tmp"]
          volumeMounts:
            - name: git-storage
              mountPath: /tmp/git-storage
---