#cloud-config
---
write_files:
  # Kubeconfig file.
  - path: /etc/kubernetes/worker-kubeconfig.yaml
    owner: root
    permissions: 0755
    content: |
      apiVersion: v1
      kind: Config
      clusters:
      - name: local
        cluster:
          server: http://172.18.18.101:8080
      users:
      - name: kubelet
      contexts:
      - context:
          cluster: local
          user: kubelet
        name: kubelet-context
      current-context: kubelet-context

coreos:
  update:
    reboot-strategy: off
  units:
    - name: etcd-member.service
      command: start
      drop-ins:
        - name: 10-etcd-member_proxy.conf
          content: |
            [Service]
            Environment="ETCD_OPTS=--proxy on --listen-client-urls http://127.0.0.1:2379 --initial-cluster=etcdserver=http://172.18.18.101:2380"
            Environment="ETCD_IMAGE_TAG=v3.0.12"
    - 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/cni/bin https://github.com/containernetworking/cni/releases/download/v0.5.1/cni-v0.5.1.tgz
        ExecStartPre=/usr/bin/tar -xvf /opt/cni/bin/cni-v0.5.1.tgz -C /opt/cni/bin
        ExecStartPre=/usr/bin/wget -N -P /opt/bin https://storage.googleapis.com/kubernetes-release/release/v1.9.6/bin/linux/amd64/kubelet
        ExecStartPre=/usr/bin/chmod +x /opt/bin/kubelet
        ExecStartPre=/usr/bin/mkdir -p /opt/cni/bin
        ExecStart=/opt/bin/kubelet \
        --address=0.0.0.0 \
        --allow-privileged=true \
        --kubeconfig /etc/kubernetes/worker-kubeconfig.yaml \
        --cluster-dns=10.100.0.10 \
        --cluster-domain=cluster.local \
        --hostname-override=$private_ipv4 \
        --volume-plugin-dir=/opt/bin/volume-plugins
        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.9.6/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://172.18.18.101:8080 \
        --cluster-cidr="192.168.128.0/18" \
        --proxy-mode=iptables \
        Restart=always
        RestartSec=10
