diff --git a/.travis.yml b/.travis.yml index c1f9539bc..a2e1b00f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,8 @@ before_install: # libseccomp in trusty is not new enough, need backports version. - sudo sh -c "echo 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse' > /etc/apt/sources.list.d/backports.list" - sudo apt-get update + # Enable ipv6 for dualstack integration test. + - sudo sysctl net.ipv6.conf.all.disable_ipv6=0 install: - sudo apt-get install btrfs-tools diff --git a/cluster/gce/cni.template b/cluster/gce/cni.template index 37f345221..1eb5f5d43 100644 --- a/cluster/gce/cni.template +++ b/cluster/gce/cni.template @@ -7,12 +7,8 @@ "mtu": 1460, "ipam": { "type": "host-local", - "subnet": "{{.PodCIDR}}", - "routes": [ - { - "dst": "0.0.0.0/0" - } - ] + "ranges": [{{range $i, $range := .PodCIDRRanges}}{{if $i}}, {{end}}[{"subnet": "{{$range}}"}]{{end}}], + "routes": [{{range $i, $route := .Routes}}{{if $i}}, {{end}}{"dst": "{{$route}}"}{{end}}] } }, { diff --git a/docs/config.md b/docs/config.md index 8f218363f..f2bb2879d 100644 --- a/docs/config.md +++ b/docs/config.md @@ -172,7 +172,7 @@ version = 2 # file will be loaded. If you want to load multiple CNI plugin config files # set max_conf_num to the number desired. Setting max_config_num to 0 is # interpreted as no limit is desired and will result in all CNI plugin - # config files being loaded from the CNI config directory. + # config files being loaded from the CNI config directory. max_conf_num = 1 # conf_template is the file path of golang template used to generate @@ -183,6 +183,7 @@ version = 2 # This is a temporary backward-compatible solution for kubenet users # who don't have a cni daemonset in production yet. # This will be deprecated when kubenet is deprecated. + # See the "CNI Config Template" section for more details. conf_template = "" # 'plugins."io.containerd.grpc.v1.cri".registry' contains config related to the registry @@ -208,6 +209,35 @@ When the annotation `io.kubernetes.cri.untrusted-workload` is set to `true` the runtime will be used. For example, see [Create an untrusted pod using Kata Containers](https://github.com/kata-containers/documentation/blob/master/how-to/how-to-use-k8s-with-cri-containerd-and-kata.md#create-an-untrusted-pod-using-kata-containers). +## CNI Config Template + +Ideally the cni config should be placed by system admin or cni daemon like calico, +weaveworks etc. However, there are still users using [kubenet](https://kubernetes.io/docs/concepts/cluster-administration/network-plugins/#kubenet) +today, who don't have a cni daemonset in production. The cni config template is +a temporary backward-compatible solution for them. This is expected to be +deprecated when kubenet is deprecated. + +The cni config template uses the [golang +template](https://golang.org/pkg/text/template/) format. Currently supported +values are: +* `.PodCIDR` is a string of the first CIDR assigned to the node. +* `.PodCIDRRanges` is a string array of all CIDRs assigned to the node. It is + usually used for + [dualstack](https://github.com/kubernetes/enhancements/blob/master/keps/sig-network/20180612-ipv4-ipv6-dual-stack.md) support. +* `.Routes` is a string array of all routes needed. It is usually used for + dualstack support or single stack but IPv4 or IPv6 is decided at runtime. + +The [golang template actions](https://golang.org/pkg/text/template/#hdr-Actions) +can be used to render the cni config. For example, you can use the following +template to add CIDRs and routes for dualstack in the CNI config: +``` +"ipam": { + "type": "host-local", + "ranges": [{{range $i, $range := .PodCIDRRanges}}{{if $i}}, {{end}}[{"subnet": "{{$range}}"}]{{end}}], + "routes": [{{range $i, $route := .Routes}}{{if $i}}, {{end}}{"dst": "{{$route}}"}{{end}}] +} +``` + ## Deprecation The config options of the CRI plugin follow the [Kubernetes deprecation policy of "admin-facing CLI components"](https://kubernetes.io/docs/reference/using-api/deprecation-policy/#deprecating-a-flag-or-cli). diff --git a/hack/install/install-cni-config.sh b/hack/install/install-cni-config.sh index b1d05263e..06226a2da 100755 --- a/hack/install/install-cni-config.sh +++ b/hack/install/install-cni-config.sh @@ -34,9 +34,17 @@ ${SUDO} bash -c 'cat >'${CNI_CONFIG_DIR}'/10-containerd-net.conflist <