---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: flannel2
  namespace: kube-system
rules:
  - apiGroups:
      - ""
    resources:
      - pods
    verbs:
      - get
  - apiGroups:
      - ""
    resources:
      - nodes
    verbs:
      - list
      - watch
  - apiGroups:
      - ""
    resources:
      - nodes/status
    verbs:
      - patch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: flannel2
  namespace: kube-system
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: flannel2
subjects:
- kind: ServiceAccount
  name: flannel2
  namespace: kube-system
---
kind: ServiceAccount
apiVersion: v1
metadata:
  name: flannel2
  namespace: kube-system
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: kube-flannel2-cfg
  namespace: kube-system
  labels:
    tier: node
    app: flannel2
data:
  flannel2-conf.json: |
    {
      "type": "flannel",
      "name": "flannel-2",
      "subnetFile": "/run/flannel/flannel2.env",
      "dataDir": "/var/lib/cni/flannel2",
      "delegate": {
        "bridge": "kbr1"
      }
    }
  net-conf.json: |
    {
      "Network": "10.144.0.0/16",
      "SubnetLen": 24,
      "SubnetMin": "10.144.0.0",
      "Backend": {
        "Type": "vxlan"
      }
    }
---
apiVersion: v1
kind: Pod
metadata:
  name: flannel-etcd
  namespace: kube-system
spec:
  containers:
  - command:
    - etcd
    - --advertise-client-urls=http://10.1.1.1:12379
    - --listen-client-urls=http://0.0.0.0:12379
    - --listen-peer-urls=http://localhost:12380
    image: quay.io/coreos/etcd:latest
    name: etcd
  hostNetwork: true
  nodeName: kube-master
---
apiVersion: batch/v1
kind: Job
metadata:
  name: flannel-etcdctl
  namespace: kube-system
spec:
  template:
    spec:
      containers:
      - name: flannel-etcdctl
        image: quay.io/coreos/etcd:latest
        command: ["etcdctl"]
        args: ["--endpoints=http://10.1.1.1:12379", "set", "/flannel2/network/config", '{ "Network": "10.5.0.0/16", "Backend": {"Type": "vxlan", "VNI": 2}}']
      hostNetwork: true
      nodeName: kube-master
      restartPolicy: Never
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: kube-flannel2-ds
  namespace: kube-system
  labels:
    tier: node
    app: flannel2
spec:
  template:
    metadata:
      labels:
        tier: node
        app: flannel2
    spec:
      hostNetwork: true
      nodeSelector:
        beta.kubernetes.io/arch: amd64
      tolerations:
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
      serviceAccountName: flannel2
      initContainers:
      - name: install-cni
        image: quay.io/coreos/flannel:v0.10.0-amd64
        command:
        - cp
        args:
        - -f
        - /etc/kube-flannel/flannel2-conf.json
        - /etc/cni/multus/net.d/10-flannel.conf
        volumeMounts:
        - name: cni
          mountPath: /etc/cni/multus/net.d
        - name: flannel2-cfg
          mountPath: /etc/kube-flannel/
      containers:
      - name: kube-flannel2
        image: quay.io/coreos/flannel:v0.10.0-amd64
        command:
        - /opt/bin/flanneld
        args:
        - --ip-masq
        - --etcd-endpoints=http://10.1.1.1:12379
        - -iface=eth1
        - -subnet-file=/run/flannel/flannel2.env
        - -etcd-prefix=/flannel2/network
        resources:
          requests:
            cpu: "100m"
            memory: "50Mi"
          limits:
            cpu: "100m"
            memory: "50Mi"
        securityContext:
          privileged: true
        env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        volumeMounts:
        - name: run
          mountPath: /run
      volumes:
        - name: run
          hostPath:
            path: /run
        - name: cni
          hostPath:
            path: /etc/cni/multus/net.d
        - name: flannel2-cfg
          configMap:
            name: kube-flannel2-cfg
---
apiVersion: "kubernetes.cni.cncf.io/v1"
kind: Network
metadata:
  name: flannel-2
