From 7699870ba4c17a957d1b534bc2592bb92fdc10e3 Mon Sep 17 00:00:00 2001 From: gjmzj Date: Thu, 28 Jun 2018 10:52:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=9B=86=E6=88=90=E5=85=B6?= =?UTF-8?q?=E4=BB=96k8s=E7=BB=84=E4=BB=B6=E7=9A=84=E7=A6=BB=E7=BA=BF?= =?UTF-8?q?=E5=AE=89=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + down/offline_images | 39 ++++++++++++++++++++++ roles/cluster-addon/defaults/main.yml | 6 ++++ roles/cluster-addon/tasks/main.yml | 47 ++++++++++++++++++++------- roles/cluster-addon/vars/main.yml | 6 ++++ 5 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 down/offline_images create mode 100644 roles/cluster-addon/vars/main.yml diff --git a/.gitignore b/.gitignore index a5b05c9..19c3ed2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ down/* !down/download.sh +!down/offline_images bin/* hosts *.crt diff --git a/down/offline_images b/down/offline_images new file mode 100644 index 0000000..4040fe3 --- /dev/null +++ b/down/offline_images @@ -0,0 +1,39 @@ +###---[basic_images ] +# dns-addon 插件 +coredns/coredns:1.0.6 +mirrorgooglecontainers/k8s-dns-kube-dns-amd64:1.14.10 +mirrorgooglecontainers/k8s-dns-dnsmasq-nanny-amd64:1.14.10 +mirrorgooglecontainers/k8s-dns-sidecar-amd64:1.14.10 +# metrics-server 插件 +mirrorgooglecontainers/metrics-server-amd64:v0.2.1 +# calico 网络插件 +calico/node:v3.0.6 +calico/cni:v2.0.5 +calico/kube-controllers:v2.0.4 +# flannel 网络插件 +jmgao1983/flannel:v0.10.0-amd64 +# kube-router 网络插件 +cloudnativelabs/kube-router +busybox +# dashboard 插件 +mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.8.3 +# pause 基础容器镜像 +mirrorgooglecontainers/pause-amd64:3.1 +# traefik ingress 镜像 +traefik:v1.6 +# heapster 插件 +mirrorgooglecontainers/heapster-grafana-amd64:v4.4.3 +mirrorgooglecontainers/heapster-amd64:v1.5.1 +mirrorgooglecontainers/heapster-influxdb-amd64:v1.3.3 + +###---[extra-images] +# helm 服务端 +jmgao1983/tiller:v2.9.1 +# efk 插件 +mirrorgooglecontainers/elasticsearch:v5.6.4 +alpine:3.6 +mirrorgooglecontainers/fluentd-elasticsearch:v2.0.2 +jmgao1983/kibana:5.6.4 +# nfs 动态PV +jmgao1983/nfs-client-provisioner:latest + diff --git a/roles/cluster-addon/defaults/main.yml b/roles/cluster-addon/defaults/main.yml index acc5995..f3ad190 100644 --- a/roles/cluster-addon/defaults/main.yml +++ b/roles/cluster-addon/defaults/main.yml @@ -1,15 +1,21 @@ # dns 自动安装,可选"coredns"和“kubedns” dns_install: "yes" dns_backend: "coredns" +kubedns_offline: "kubedns_1.14.10.tar" +coredns_offline: "coredns_1.0.6.tar" # metric server 自动安装 metricsserver_install: "yes" +metricsserver_offline: "metrics-server_v0.2.1.tar" # dashboard 自动安装 dashboard_install: "yes" +dashboard_offline: "dashboard_v1.8.3.tar" # traefik-ingress 自动安装 ingress_install: "no" +ingress_backend: "traefik" +traefik_offline: "traefik_v1.6.tar" # heapster 自动安装 heapster_install: "no" diff --git a/roles/cluster-addon/tasks/main.yml b/roles/cluster-addon/tasks/main.yml index b50473b..385e9d4 100644 --- a/roles/cluster-addon/tasks/main.yml +++ b/roles/cluster-addon/tasks/main.yml @@ -10,28 +10,53 @@ command: "{{ bin_dir }}/kubectl get pod -n kube-system" register: pod_info -- name: 创建 {{ dns_backend }}部署 - shell: "sleep 5; {{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/{{ dns_backend }}" - when: 'dns_backend not in pod_info.stdout and dns_install == "yes"' +- block: + - name: 尝试推送离线{{ dns_backend }}镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ dns_offline }} dest=/opt/kube/images/{{ dns_offline }} + - name: 导入{{ dns_backend }}的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ dns_offline }}" + - name: 创建{{ dns_backend }}部署 + shell: "sleep 5; {{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/{{ dns_backend }}" + when: '"kube-dns" not in pod_info.stdout and "coredns" not in pod_info.stdout and dns_install == "yes"' ignore_errors: true -- name: 创建 metrics-server部署 - shell: "sleep 5; {{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/metrics-server" +- block: + - name: 尝试推送离线 metrics-server镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ metricsserver_offline }} dest=/opt/kube/images/{{ metricsserver_offline }} + - name: 导入 metrics-server的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ metricsserver_offline }}" + - name: 创建 metrics-server部署 + shell: "sleep 5; {{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/metrics-server" when: '"metrics-server" not in pod_info.stdout and metricsserver_install == "yes"' ignore_errors: true -- name: 创建 dashboard部署 - shell: "sleep 5; {{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/dashboard" +- block: + - name: 尝试推送离线 dashboard镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ dashboard_offline }} dest=/opt/kube/images/{{ dashboard_offline }} + - name: 导入 dashboard的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ dashboard_offline }}" + - name: 创建 dashboard部署 + shell: "sleep 5; {{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/dashboard" when: '"kubernetes-dashboard" not in pod_info.stdout and dashboard_install == "yes"' ignore_errors: true -- name: 创建 traefik-ingress部署 - shell: "sleep 5; {{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/ingress/traefik-ingress.yaml" +- block: + - name: 尝试推送离线 traefik镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ traefik_offline }} dest=/opt/kube/images/{{ traefik_offline }} + - name: 导入 traefik的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ traefik_offline }}" + - name: 创建 traefik部署 + shell: "sleep 5; {{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/ingress/traefik-ingress.yaml" when: '"traefik-ingress-controller" not in pod_info.stdout and ingress_install == "yes"' ignore_errors: true -- name: 创建 heapster部署 - shell: "sleep 5; {{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/heapster" +- block: + - name: 尝试推送离线 heapster镜像(若执行失败,可忽略) + copy: src={{ base_dir }}/down/{{ heapster_offline }} dest=/opt/kube/images/{{ heapster_offline }} + - name: 导入 heapster的离线镜像(若执行失败,可忽略) + shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ heapster_offline }}" + - name: 创建 heapster部署 + shell: "sleep 5; {{ bin_dir }}/kubectl apply -f {{ base_dir }}/manifests/heapster" when: '"heapster" not in pod_info.stdout and heapster_install == "yes"' ignore_errors: true diff --git a/roles/cluster-addon/vars/main.yml b/roles/cluster-addon/vars/main.yml new file mode 100644 index 0000000..76d7617 --- /dev/null +++ b/roles/cluster-addon/vars/main.yml @@ -0,0 +1,6 @@ +dns_offline: "{%- if dns_backend == 'coredns' -%} \ + {{ coredns_offline }} \ + {%- else -%} \ + {{ kubedns_offline }} \ + {%- endif -%}" +