#cloud-config
---
coreos:
  update:
    reboot-strategy: off
  units:
    - name: etcd-member.service
      command: start
      drop-ins:
        - name: 10-etcd.conf
          content: |
            [Service]
            Environment="ETCD_OPTS=--name \"etcdserver\" --listen-client-urls=http://0.0.0.0:2379 --advertise-client-urls=http://$private_ipv4:2379 --initial-cluster=etcdserver=http://$private_ipv4:2380 --initial-advertise-peer-urls=http://$private_ipv4:2380 --listen-client-urls=http://0.0.0.0:2379,http://0.0.0.0:4001 --listen-peer-urls=http://0.0.0.0:2380"
            Environment="ETCD_IMAGE_TAG=v3.0.12"

    - name: kube-apiserver.service
      command: start
      content: |
        [Unit]
        Description=Kubernetes API Server
        Documentation=https://github.com/GoogleCloudPlatform/kubernetes
        Requires=etcd-member.service
        After=etcd-member.service
        [Service]
        TimeoutStartSec=1800
        ExecStartPre=/usr/bin/wget -N -P /opt/bin https://storage.googleapis.com/kubernetes-release/release/v1.6.2/bin/linux/amd64/kubectl
        ExecStartPre=/usr/bin/wget -N -P /opt/bin https://storage.googleapis.com/kubernetes-release/release/v1.6.2/bin/linux/amd64/kube-apiserver
        ExecStartPre=/usr/bin/chmod +x /opt/bin/kubectl
        ExecStartPre=/usr/bin/chmod +x /opt/bin/kube-apiserver
        ExecStart=/opt/bin/kube-apiserver \
        --allow-privileged=true \
        --etcd-servers=http://$private_ipv4:2379 \
        --runtime-config=extensions/v1beta1=true,extensions/v1beta1/networkpolicies=true \
        --insecure-bind-address=0.0.0.0 \
        --admission-control=NamespaceLifecycle,LimitRanger,ServiceAccount,ResourceQuota \
        --advertise-address=$private_ipv4 \
        --service-cluster-ip-range=10.100.0.0/24 \
        --logtostderr=true
        Restart=always
        RestartSec=10

    - name: kube-controller-manager.service
      command: start
      content: |
        [Unit]
        Description=Kubernetes Controller Manager
        Documentation=https://github.com/GoogleCloudPlatform/kubernetes
        Requires=kube-apiserver.service
        After=kube-apiserver.service
        [Service]
        TimeoutStartSec=1800
        ExecStartPre=/usr/bin/wget -N -P /opt/bin https://storage.googleapis.com/kubernetes-release/release/v1.6.2/bin/linux/amd64/kube-controller-manager
        ExecStartPre=/usr/bin/chmod +x /opt/bin/kube-controller-manager
        # --cluster-cidr must match the IP Pool defined in the manifest
        ExecStart=/opt/bin/kube-controller-manager \
        --master=$private_ipv4:8080 \
        --service-account-private-key-file=/var/run/kubernetes/apiserver.key \
        --root-ca-file=/var/run/kubernetes/apiserver.crt \
        --logtostderr=true \
        --allocate-node-cidrs=true \
        --cluster-cidr="192.168.0.0/16"
        Restart=always
        RestartSec=10

    - name: kube-scheduler.service
      command: start
      content: |
        [Unit]
        Description=Kubernetes Scheduler
        Documentation=https://github.com/GoogleCloudPlatform/kubernetes
        Requires=kube-apiserver.service
        After=kube-apiserver.service
        [Service]
        TimeoutStartSec=1800
        ExecStartPre=/usr/bin/wget -N -P /opt/bin https://storage.googleapis.com/kubernetes-release/release/v1.6.2/bin/linux/amd64/kube-scheduler
        ExecStartPre=/usr/bin/chmod +x /opt/bin/kube-scheduler
        ExecStart=/opt/bin/kube-scheduler --master=$private_ipv4:8080
        Restart=always
        RestartSec=10

    - name: kubelet.service
      runtime: true
      command: start
      content: |
        [Unit]
        Description=Kubernetes Kubelet
        Documentation=https://github.com/kubernetes/kubernetes
        After=docker.service
        Requires=docker.service

        [Service]
        TimeoutStartSec=1800
        ExecStartPre=/usr/bin/wget -N -P /opt/bin https://storage.googleapis.com/kubernetes-release/release/v1.6.2/bin/linux/amd64/kubelet
        ExecStartPre=/usr/bin/chmod +x /opt/bin/kubelet
        ExecStart=/opt/bin/kubelet \
        --address=0.0.0.0 \
        --allow-privileged=true \
        --api-servers=http://127.0.0.1:8080 \
        --cluster-dns=10.100.0.10 \
        --cluster-domain=cluster.local \
        --hostname-override=$private_ipv4 \
        --logtostderr=true \
        --register-node=true \
        --register-schedulable=false
        Restart=always
        RestartSec=10

        [Install]
        WantedBy=multi-user.target

    - name: kube-proxy.service
      command: start
      content: |
        [Unit]
        Description=Kubernetes Proxy
        Documentation=https://github.com/GoogleCloudPlatform/kubernetes
        Requires=kubelet.service
        After=kubelet.service
        [Service]
        TimeoutStartSec=1800
        ExecStartPre=/usr/bin/wget -N -P /opt/bin  https://storage.googleapis.com/kubernetes-release/release/v1.6.2/bin/linux/amd64/kube-proxy
        ExecStartPre=/usr/bin/chmod +x /opt/bin/kube-proxy
        # --cluster-cidr must match the IP Pool defined in the manifest
        ExecStart=/opt/bin/kube-proxy \
        --master=http://$private_ipv4:8080 \
        --cluster-cidr="192.168.0.0/16" \
        --proxy-mode=iptables \
        --logtostderr=true
        Restart=always
        RestartSec=10
