From 813db54a2f95db81b401ca8f76e4ce877cb06318 Mon Sep 17 00:00:00 2001 From: gjmzj Date: Sun, 9 Jun 2019 15:55:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=9F=E5=BC=83ansible=20hosts=E4=B8=AD?= =?UTF-8?q?=E5=8F=98=E9=87=8FCLUSTER=5FDNS=5FSVC=5FIP=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/hosts.allinone.example | 6 ------ example/hosts.allinone.example.en | 6 ------ example/hosts.cloud.example | 6 ------ example/hosts.cloud.example.en | 6 ------ example/hosts.m-masters.example | 6 ------ example/hosts.m-masters.example.en | 6 ------ example/hosts.s-master.example | 6 ------ example/hosts.s-master.example.en | 6 ------ roles/cluster-addon/tasks/main.yml | 8 ++++++++ roles/kube-master/tasks/main.yml | 10 ++++++++++ roles/kube-node/tasks/main.yml | 10 ++++++++++ 11 files changed, 28 insertions(+), 48 deletions(-) diff --git a/example/hosts.allinone.example b/example/hosts.allinone.example index cc689e7..4fbcc01 100644 --- a/example/hosts.allinone.example +++ b/example/hosts.allinone.example @@ -47,12 +47,6 @@ CLUSTER_CIDR="172.20.0.0/16" # 服务端口范围 (NodePort Range) NODE_PORT_RANGE="20000-40000" -# kubernetes 服务 IP (预分配,一般是 SERVICE_CIDR 中第一个IP) -CLUSTER_KUBERNETES_SVC_IP="10.68.0.1" - -# 集群 DNS 服务 IP (从 SERVICE_CIDR 中预分配) -CLUSTER_DNS_SVC_IP="10.68.0.2" - # 集群 DNS 域名 CLUSTER_DNS_DOMAIN="cluster.local." diff --git a/example/hosts.allinone.example.en b/example/hosts.allinone.example.en index c289ade..fcdf419 100644 --- a/example/hosts.allinone.example.en +++ b/example/hosts.allinone.example.en @@ -48,12 +48,6 @@ CLUSTER_CIDR="172.20.0.0/16" # NodePort Range NODE_PORT_RANGE="20000-40000" -# Kubernetes SVC IP (usually assigned with the first available IP of 'SERVICE_CIDR') -CLUSTER_KUBERNETES_SVC_IP="10.68.0.1" - -# Cluster DNS Server's IP (assigned with an available IP of 'SERVICE_CIDR') -CLUSTER_DNS_SVC_IP="10.68.0.2" - # Cluster DNS Domain CLUSTER_DNS_DOMAIN="cluster.local." diff --git a/example/hosts.cloud.example b/example/hosts.cloud.example index 4202d4f..459ce91 100644 --- a/example/hosts.cloud.example +++ b/example/hosts.cloud.example @@ -47,12 +47,6 @@ CLUSTER_CIDR="172.20.0.0/16" # 服务端口范围 (NodePort Range) NODE_PORT_RANGE="20000-40000" -# kubernetes 服务 IP (预分配,一般是 SERVICE_CIDR 中第一个IP) -CLUSTER_KUBERNETES_SVC_IP="10.68.0.1" - -# 集群 DNS 服务 IP (从 SERVICE_CIDR 中预分配) -CLUSTER_DNS_SVC_IP="10.68.0.2" - # 集群 DNS 域名 CLUSTER_DNS_DOMAIN="cluster.local." diff --git a/example/hosts.cloud.example.en b/example/hosts.cloud.example.en index ddd4090..80bd4e0 100644 --- a/example/hosts.cloud.example.en +++ b/example/hosts.cloud.example.en @@ -48,12 +48,6 @@ CLUSTER_CIDR="172.20.0.0/16" # NodePort Range NODE_PORT_RANGE="20000-40000" -# Kubernetes SVC IP (usually assigned with the first available IP of 'SERVICE_CIDR') -CLUSTER_KUBERNETES_SVC_IP="10.68.0.1" - -# Cluster DNS Server's IP (assigned with an available IP of 'SERVICE_CIDR') -CLUSTER_DNS_SVC_IP="10.68.0.2" - # Cluster DNS Domain CLUSTER_DNS_DOMAIN="cluster.local." diff --git a/example/hosts.m-masters.example b/example/hosts.m-masters.example index 7b3c8ec..a69ef63 100644 --- a/example/hosts.m-masters.example +++ b/example/hosts.m-masters.example @@ -57,12 +57,6 @@ CLUSTER_CIDR="172.20.0.0/16" # 服务端口范围 (NodePort Range) NODE_PORT_RANGE="20000-40000" -# kubernetes 服务 IP (预分配,一般是 SERVICE_CIDR 中第一个IP) -CLUSTER_KUBERNETES_SVC_IP="10.68.0.1" - -# 集群 DNS 服务 IP (从 SERVICE_CIDR 中预分配) -CLUSTER_DNS_SVC_IP="10.68.0.2" - # 集群 DNS 域名 CLUSTER_DNS_DOMAIN="cluster.local." diff --git a/example/hosts.m-masters.example.en b/example/hosts.m-masters.example.en index 54efca0..65c12da 100644 --- a/example/hosts.m-masters.example.en +++ b/example/hosts.m-masters.example.en @@ -58,12 +58,6 @@ CLUSTER_CIDR="172.20.0.0/16" # NodePort Range NODE_PORT_RANGE="20000-40000" -# Kubernetes SVC IP (usually assigned with the first available IP of 'SERVICE_CIDR') -CLUSTER_KUBERNETES_SVC_IP="10.68.0.1" - -# Cluster DNS Server's IP (assigned with an available IP of 'SERVICE_CIDR') -CLUSTER_DNS_SVC_IP="10.68.0.2" - # Cluster DNS Domain CLUSTER_DNS_DOMAIN="cluster.local." diff --git a/example/hosts.s-master.example b/example/hosts.s-master.example index 846d48d..6877b3d 100644 --- a/example/hosts.s-master.example +++ b/example/hosts.s-master.example @@ -48,12 +48,6 @@ CLUSTER_CIDR="172.20.0.0/16" # 服务端口范围 (NodePort Range) NODE_PORT_RANGE="20000-40000" -# kubernetes 服务 IP (预分配,一般是 SERVICE_CIDR 中第一个IP) -CLUSTER_KUBERNETES_SVC_IP="10.68.0.1" - -# 集群 DNS 服务 IP (从 SERVICE_CIDR 中预分配) -CLUSTER_DNS_SVC_IP="10.68.0.2" - # 集群 DNS 域名 CLUSTER_DNS_DOMAIN="cluster.local." diff --git a/example/hosts.s-master.example.en b/example/hosts.s-master.example.en index 155ea2e..6ac0ee3 100644 --- a/example/hosts.s-master.example.en +++ b/example/hosts.s-master.example.en @@ -49,12 +49,6 @@ CLUSTER_CIDR="172.20.0.0/16" # NodePort Range NODE_PORT_RANGE="20000-40000" -# Kubernetes SVC IP (usually assigned with the first available IP of 'SERVICE_CIDR') -CLUSTER_KUBERNETES_SVC_IP="10.68.0.1" - -# Cluster DNS Server's IP (assigned with an available IP of 'SERVICE_CIDR') -CLUSTER_DNS_SVC_IP="10.68.0.2" - # Cluster DNS Domain CLUSTER_DNS_DOMAIN="cluster.local." diff --git a/roles/cluster-addon/tasks/main.yml b/roles/cluster-addon/tasks/main.yml index a2bfdae..302fcc5 100644 --- a/roles/cluster-addon/tasks/main.yml +++ b/roles/cluster-addon/tasks/main.yml @@ -1,3 +1,11 @@ +# 设置 dns svc ip (这里选用 SERVICE_CIDR 中第2个IP) +- name: 注册变量 DNS_SVC_IP + shell: echo {{ SERVICE_CIDR }}|cut -d/ -f1|awk -F. '{print $1"."$2"."$3"."$4+2}' + register: DNS_SVC_IP + +- name: 设置变量 CLUSTER_DNS_SVC_IP + set_fact: CLUSTER_DNS_SVC_IP={{ DNS_SVC_IP.stdout }} + - block: - name: 在deploy 节点创建相关目录 file: path={{ item }} state=directory diff --git a/roles/kube-master/tasks/main.yml b/roles/kube-master/tasks/main.yml index 6a63bd2..c4dfa71 100644 --- a/roles/kube-master/tasks/main.yml +++ b/roles/kube-master/tasks/main.yml @@ -16,6 +16,16 @@ - ca-config.json delegate_to: "{{ groups.deploy[0] }}" +# 设置 kubernetes svc ip (一般是 SERVICE_CIDR 中第一个IP) +- name: 注册变量 KUBERNETES_SVC_IP + shell: echo {{ SERVICE_CIDR }}|cut -d/ -f1|awk -F. '{print $1"."$2"."$3"."$4+1}' + register: KUBERNETES_SVC_IP + tags: change_cert + +- name: 设置变量 CLUSTER_KUBERNETES_SVC_IP + set_fact: CLUSTER_KUBERNETES_SVC_IP={{ KUBERNETES_SVC_IP.stdout }} + tags: change_cert + - name: 创建 kubernetes 证书签名请求 template: src=kubernetes-csr.json.j2 dest={{ ca_dir }}/kubernetes-csr.json tags: change_cert diff --git a/roles/kube-node/tasks/main.yml b/roles/kube-node/tasks/main.yml index 0146506..7d0db74 100644 --- a/roles/kube-node/tasks/main.yml +++ b/roles/kube-node/tasks/main.yml @@ -89,6 +89,16 @@ - name: 准备 cni配置文件 template: src=cni-default.conf.j2 dest=/etc/cni/net.d/10-default.conf +# 设置 dns svc ip (这里选用 SERVICE_CIDR 中第2个IP) +- name: 注册变量 DNS_SVC_IP + shell: echo {{ SERVICE_CIDR }}|cut -d/ -f1|awk -F. '{print $1"."$2"."$3"."$4+2}' + register: DNS_SVC_IP + tags: restart_node + +- name: 设置变量 CLUSTER_DNS_SVC_IP + set_fact: CLUSTER_DNS_SVC_IP={{ DNS_SVC_IP.stdout }} + tags: restart_node + - name: 创建kubelet的systemd unit文件 template: src=kubelet.service.j2 dest=/etc/systemd/system/kubelet.service tags: upgrade_k8s, restart_node