#cloud-config

coreos:
  units:
    - name: kube-apiserver.service
      command: start
      content: |
        [Unit]
        After=opt-kubernetes.mount etcd.service
        ConditionFileIsExecutable=/opt/kubernetes/bin/kube-apiserver
        Description=Kubernetes API Server
        Documentation=https://github.com/GoogleCloudPlatform/kubernetes
        Requires=opt-kubernetes.mount etcd.service

        [Service]
        ExecStart=/opt/kubernetes/bin/kube-apiserver \
        --address=0.0.0.0 \
        --port=8080 \
        --etcd_servers=http://127.0.0.1:4001 \
        --kubelet_port=10250 \
        --portal_net=${PORTAL_NET}
        Restart=always
        RestartSec=2

        [Install]
        WantedBy=multi-user.target
    - name: kube-controller-manager.service
      command: start
      content: |
        [Unit]
        After=opt-kubernetes.mount kube-apiserver.service
        ConditionFileIsExecutable=/opt/kubernetes/bin/kube-controller-manager
        Description=Kubernetes Controller Manager
        Documentation=https://github.com/GoogleCloudPlatform/kubernetes
        Requires=opt-kubernetes.mount kube-apiserver.service

        [Service]
        ExecStart=/opt/kubernetes/bin/kube-controller-manager \
        --master=127.0.0.1:8080 \
        --machines=${machines}
        Restart=always
        RestartSec=2

        [Install]
        WantedBy=multi-user.target
    - name: kube-scheduler.service
      command: start
      content: |
        [Unit]
        After=opt-kubernetes.mount kube-apiserver.service
        ConditionFileIsExecutable=/opt/kubernetes/bin/kube-scheduler
        Description=Kubernetes Scheduler
        Documentation=https://github.com/GoogleCloudPlatform/kubernetes
        Requires=opt-kubernetes.mount kube-apiserver.service

        [Service]
        ExecStart=/opt/kubernetes/bin/kube-scheduler \
        --master=127.0.0.1:8080
        Restart=always
        RestartSec=2

        [Install]
        WantedBy=multi-user.target
    - name: kube-addons.service
      command: start
      content: |
        [Unit]
        After=opt-kubernetes.mount kube-apiserver.service
        ConditionPathIsDirectory=/opt/kubernetes/addons
        Description=Kubernetes addons
        Documentation=https://github.com/GoogleCloudPlatform/kubernetes
        Requires=opt-kubernetes.mount
        Wants=kube-apiserver.service

        [Service]
        Type=oneshot
        ExecStartPre=/bin/bash -c 'while [[ \"\$(curl -s http://127.0.0.1:8080/healthz)\" != \"ok\" ]]; do sleep 1; done'
        ExecStartPre=/bin/sleep 10
        ExecStart=/opt/kubernetes/bin/kubectl create -f /opt/kubernetes/addons
        ExecStop=/opt/kubernetes/bin/kubectl stop -f /opt/kubernetes/addons
        RemainAfterExit=yes

        [Install]
        WantedBy=multi-user.target
