#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://kubernetes-master:8080
      users:
      - name: kubelet
      contexts:
      - context:
          cluster: local
          user: kubelet
        name: kubelet-context
      current-context: kubelet-context

coreos:
  etcd2:
    proxy: on 
    listen-client-urls: http://127.0.0.1:2379
    initial-cluster: etcdserver=http://kubernetes-master:2380
  fleet:
    metadata: "role=node"
    etcd_servers: "http://127.0.0.1:2379"
  update:
    reboot-strategy: off
  units:
    - name: etcd2.service
      command: start
    - name: fleet.service
      command: start

    - 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]
        ExecStartPre=/usr/bin/wget -N -P /opt/cni/bin https://github.com/containernetworking/cni/releases/download/v0.3.0/cni-v0.3.0.tgz
        ExecStartPre=/usr/bin/tar -xvf /opt/cni/bin/cni-v0.3.0.tgz -C /opt/cni/bin  
        ExecStartPre=/usr/bin/wget -N -P /opt/bin https://storage.googleapis.com/kubernetes-release/release/v1.4.0-alpha.3/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 \
        --api-servers=http://kubernetes-master:8080 \
        --cluster-dns=10.100.0.10 \
        --cluster-domain=cluster.local \
        --config=/etc/kubernetes/manifests \
        --hostname-override=$private_ipv4 \
        --logtostderr=true \
        --network-plugin=cni \
        --network-plugin-dir=/etc/cni/net.d
        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]
        ExecStartPre=/usr/bin/wget -N -P /opt/bin  https://storage.googleapis.com/kubernetes-release/release/v1.4.0-alpha.3/bin/linux/amd64/kube-proxy
        ExecStartPre=/usr/bin/chmod +x /opt/bin/kube-proxy
        ExecStart=/opt/bin/kube-proxy \
        --master=http://kubernetes-master:8080 \
        --cluster-cidr="192.168.0.0/16" \
        --proxy-mode=iptables \
        --logtostderr=true
        Restart=always
        RestartSec=10
