diff --git a/cluster/common.sh b/cluster/common.sh index 5b0292b4c80..550fb485c7f 100755 --- a/cluster/common.sh +++ b/cluster/common.sh @@ -899,12 +899,17 @@ EOF cat >>$file <>$file <>$file <>/srv/salt-overlay/pillar/cluster-params.sls node_labels: '$(echo "${NODE_LABELS}" | sed -e "s/'/''/g")' +EOF + fi + if [ -n "${NON_MASTER_NODE_LABELS:-}" ]; then + cat <>/srv/salt-overlay/pillar/cluster-params.sls +non_master_node_labels: '$(echo "${NON_MASTER_NODE_LABELS}" | sed -e "s/'/''/g")' EOF fi if [ -n "${NODE_TAINTS:-}" ]; then diff --git a/cluster/gce/container-linux/configure-helper.sh b/cluster/gce/container-linux/configure-helper.sh index 6cc5ea1d9a3..b5633ee5c63 100755 --- a/cluster/gce/container-linux/configure-helper.sh +++ b/cluster/gce/container-linux/configure-helper.sh @@ -598,6 +598,9 @@ function start-kubelet { if [[ -n "${NODE_LABELS:-}" ]]; then node_labels="${node_labels:+${node_labels},}${NODE_LABELS}" fi + if [[ -n "${NON_MASTER_NODE_LABELS:-}" && "${KUBERNETES_MASTER:-}" != "true" ]]; then + node_labels="${node_labels:+${node_labels},}${NON_MASTER_NODE_LABELS}" + fi if [[ -n "${node_labels:-}" ]]; then flags+=" --node-labels=${node_labels}" fi diff --git a/cluster/gce/gci/configure-helper.sh b/cluster/gce/gci/configure-helper.sh index 48ea17f6cee..262c86265e1 100644 --- a/cluster/gce/gci/configure-helper.sh +++ b/cluster/gce/gci/configure-helper.sh @@ -60,6 +60,20 @@ function config-ip-firewall { if [[ "${ENABLE_METADATA_CONCEALMENT:-}" == "true" ]]; then iptables -A KUBE-METADATA-SERVER -j DROP fi + + # Flush iptables nat table + iptables -t nat -F || true + + if [[ "${NETWORK_POLICY_PROVIDER:-}" == "calico" && "${KUBERNETES_MASTER:-}" == false ]]; then + echo "Add rules for ip masquerade" + iptables -t nat -N IP-MASQ + iptables -t nat -A POSTROUTING -m comment --comment "ip-masq: ensure nat POSTROUTING directs all non-LOCAL destination traffic to our custom IP-MASQ chain" -m addrtype ! --dst-type LOCAL -j IP-MASQ + iptables -t nat -A IP-MASQ -d 169.254.0.0/16 -m comment --comment "ip-masq: local traffic is not subject to MASQUERADE" -j RETURN + iptables -t nat -A IP-MASQ -d 10.0.0.0/8 -m comment --comment "ip-masq: local traffic is not subject to MASQUERADE" -j RETURN + iptables -t nat -A IP-MASQ -d 172.16.0.0/12 -m comment --comment "ip-masq: local traffic is not subject to MASQUERADE" -j RETURN + iptables -t nat -A IP-MASQ -d 192.168.0.0/16 -m comment --comment "ip-masq: local traffic is not subject to MASQUERADE" -j RETURN + iptables -t nat -A IP-MASQ -m comment --comment "ip-masq: outbound traffic is subject to MASQUERADE (must be last in chain)" -j MASQUERADE + fi } function create-dirs { @@ -938,7 +952,9 @@ function start-kubelet { flags+=" --cni-bin-dir=/home/kubernetes/bin" if [[ "${NETWORK_POLICY_PROVIDER:-}" == "calico" ]]; then # Calico uses CNI always. - if [[ "${KUBERNETES_PRIVATE_MASTER:-}" == "true" ]]; then + # Keep KUBERNETES_PRIVATE_MASTER for backward compatibility. + # Note that network policy won't work for master node. + if [[ "${KUBERNETES_PRIVATE_MASTER:-}" == "true" || "${KUBERNETES_MASTER:-}" == "true" ]]; then flags+=" --network-plugin=${NETWORK_PROVIDER}" else flags+=" --network-plugin=cni" @@ -971,6 +987,9 @@ function start-kubelet { if [[ -n "${NODE_LABELS:-}" ]]; then node_labels="${node_labels:+${node_labels},}${NODE_LABELS}" fi + if [[ -n "${NON_MASTER_NODE_LABELS:-}" && "${KUBERNETES_MASTER:-}" != "true" ]]; then + node_labels="${node_labels:+${node_labels},}${NON_MASTER_NODE_LABELS}" + fi if [[ -n "${node_labels:-}" ]]; then flags+=" --node-labels=${node_labels}" fi @@ -1007,9 +1026,6 @@ ExecStart=${kubelet_bin} \$KUBELET_OPTS WantedBy=multi-user.target EOF - # Flush iptables nat table - iptables -t nat -F || true - systemctl start kubelet.service } diff --git a/cluster/saltbase/salt/kubelet/default b/cluster/saltbase/salt/kubelet/default index c0c31829f23..27511061e84 100644 --- a/cluster/saltbase/salt/kubelet/default +++ b/cluster/saltbase/salt/kubelet/default @@ -171,6 +171,9 @@ {% set kube_proxy_ds_label = "beta.kubernetes.io/kube-proxy-ds-ready=true," %} {% endif %} {% set node_labels = kube_proxy_ds_label + pillar['node_labels'] %} +{% if grains['roles'][0] != 'kubernetes-master' and pillar['non_master_node_labels'] is defined -%} + {% set node_labels = pillar['non_master_node_labels'] + "," + node_labels %} +{% endif %} {% if node_labels != "" %} {% set node_labels="--node-labels=" + node_labels %} {% endif %}