Skip to content
This repository has been archived by the owner on Oct 9, 2022. It is now read-only.

Commit

Permalink
fix多主节点部署问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgao1983 committed Nov 20, 2017
1 parent d73cfa8 commit 7a4cd9a
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 30 deletions.
4 changes: 0 additions & 4 deletions 00.deploy.yml

This file was deleted.

15 changes: 12 additions & 3 deletions 01.prepare.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#
- hosts: kube-cluster
# 在deploy节点生成CA相关证书,以供整个集群使用
- hosts: deploy
roles:
- deploy

#集群节点的公共配置任务
- hosts:
- kube-cluster
- etcd
- lb
roles:
- prepare
#

#[可选]多master部署时的负载均衡配置
- hosts: lb
roles:
- lb
4 changes: 3 additions & 1 deletion 03.kubectl.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- hosts: kube-cluster
- hosts:
- kube-cluster
- lb
roles:
- kubectl
12 changes: 10 additions & 2 deletions 90.setup.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# 在deploy节点生成CA相关证书,以供整个集群使用
- hosts: deploy
roles:
- deploy

- hosts: kube-cluster
#集群节点的公共配置任务
- hosts:
- kube-cluster
- etcd
- lb
roles:
- prepare

#[可选]多master部署时的负载均衡配置
- hosts: lb
roles:
- lb
Expand All @@ -14,7 +20,9 @@
roles:
- etcd

- hosts: kube-cluster
- hosts:
- kube-cluster
- lb
roles:
- kubectl

Expand Down
4 changes: 3 additions & 1 deletion 95.clean.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
- hosts: kube-node
- hosts:
- kube-node
- lb
tasks:
- name: stop kube-node service
shell: "systemctl stop kubelet kube-proxy flanneld docker"
Expand Down
10 changes: 9 additions & 1 deletion example/hosts.m-masters.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
192.168.1.1

# 负载均衡至少两个节点,安装 haproxy+keepalived
# 根据master节点数量同步修改roles/lb/templates/haproxy.cfg.j2
[lb]
192.168.1.1 LB_NAME=lb1 LB_IF="eth0" LB_ROLE=master
192.168.1.2 LB_NAME=lb2 LB_IF="eth0" LB_ROLE=backup
[lb:vars]
LB_EP1="192.168.1.1:6443" # api-server 实际成员地址端口
LB_EP2="192.168.1.2:6443" # api-server 实际成员地址端口
#LB_EP3="192.168.1.3:6443" # api-server 实际成员地址端口
MASTER_IP="192.168.1.100" # api-server 虚地址
MASTER_PORT="8443" # api-server 服务端口

Expand All @@ -34,9 +36,15 @@ MASTER_PORT="8443" # api-server 服务端口
[kube-cluster:children]
kube-node
kube-master

[k8s:children]
deploy
lb
etcd
kube-node
kube-master

[kube-cluster:vars]
[k8s:vars]
# ---------集群主要参数---------------
#集群 MASTER IP, 需要外部负载均衡,一般为VIP地址
MASTER_IP="192.168.1.100"
Expand Down
2 changes: 1 addition & 1 deletion manifests/dashboard/kubernetes-dashboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ spec:
containers:
- name: kubernetes-dashboard
#image: gcr.io/google_containers/kubernetes-dashboard-amd64:v1.6.3
image: harbor.tf56.lo/k8s/kubernetes-dashboard-amd64:v1.6.3
image: mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.6.3
ports:
- containerPort: 9090
protocol: TCP
Expand Down
2 changes: 1 addition & 1 deletion manifests/heapster/grafana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
containers:
- name: grafana
#image: gcr.io/google_containers/heapster-grafana-amd64:v4.2.0
image: harbor.tf56.lo/k8s/heapster-grafana-amd64:v4.4.3
image: mirrorgooglecontainers/heapster-grafana-amd64:v4.4.3
ports:
- containerPort: 3000
protocol: TCP
Expand Down
4 changes: 2 additions & 2 deletions manifests/heapster/heapster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
namespace: kube-system
---

apiVersion: rbac.authorization.k8s.io/v1
apiVersion: rbac.authorization.k8s.io/v1alpha1
kind: ClusterRoleBinding
metadata:
name: heapster
Expand Down Expand Up @@ -37,7 +37,7 @@ spec:
containers:
- name: heapster
#image: gcr.io/google_containers/heapster-amd64:v1.3.0
image: harbor.tf56.lo/k8s/heapster-amd64:v1.3.0
image: mirrorgooglecontainers/heapster-amd64:v1.3.0
imagePullPolicy: IfNotPresent
command:
- /heapster
Expand Down
2 changes: 1 addition & 1 deletion manifests/heapster/influxdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
containers:
- name: influxdb
#image: gcr.io/google_containers/heapster-influxdb-amd64:v1.1.1
image: harbor.tf56.lo/k8s/heapster-influxdb-amd64:v1.1.1
image: mirrorgooglecontainers/heapster-influxdb-amd64:v1.1.1
volumeMounts:
- mountPath: /data
name: influxdb-storage
Expand Down
10 changes: 5 additions & 5 deletions manifests/kubedns/kubedns-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ spec:
optional: true
containers:
- name: kubedns
image: harbor.tf56.lo/k8s/k8s-dns-kube-dns-amd64:1.14.4
image: mirrorgooglecontainers/k8s-dns-kube-dns-amd64:1.14.4
resources:
# TODO: Set memory limits when we've profiled the container for large
# clusters, then set request = limit to keep this container in
Expand Down Expand Up @@ -107,7 +107,7 @@ spec:
- name: kube-dns-config
mountPath: /kube-dns-config
- name: dnsmasq
image: harbor.tf56.lo/k8s/k8s-dns-dnsmasq-nanny-amd64:1.14.4
image: mirrorgooglecontainers/k8s-dns-dnsmasq-nanny-amd64:1.14.4
livenessProbe:
httpGet:
path: /healthcheck/dnsmasq
Expand Down Expand Up @@ -145,7 +145,7 @@ spec:
- name: kube-dns-config
mountPath: /etc/k8s/dns/dnsmasq-nanny
- name: sidecar
image: harbor.tf56.lo/k8s/k8s-dns-sidecar-amd64:1.14.4
image: mirrorgooglecontainers/k8s-dns-sidecar-amd64:1.14.4
livenessProbe:
httpGet:
path: /metrics
Expand All @@ -168,7 +168,7 @@ spec:
requests:
memory: 20Mi
cpu: 10m
imagePullSecrets:
- name: harbor-key1
#imagePullSecrets:
#- name: harbor-key1
dnsPolicy: Default # Don't use cluster DNS.
serviceAccountName: kube-dns
8 changes: 6 additions & 2 deletions roles/flanneld/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@

- name: 准备脚本写入集群 Pod 网段信息到 etcd
template: src=save_to_etcd.sh.j2 dest=/tmp/save_to_etcd.sh
when: NODE_NAME is defined and NODE_NAME == "etcd1"
when: NODE_ID is defined and NODE_ID == "node1"

- name: 准备etcdctl 用于写入pod 网段信息
copy: src={{ base_dir }}/bin/etcdctl dest={{ bin_dir }}/etcdctl mode=0755
when: NODE_ID is defined and NODE_ID == "node1"

- name: 执行脚本写入集群 Pod 网段信息
shell: /bin/bash /tmp/save_to_etcd.sh
when: NODE_NAME is defined and NODE_NAME == "etcd1"
when: NODE_ID is defined and NODE_ID == "node1"

- name: 下载flanneld二进制
copy: src={{ base_dir }}/bin/{{ item }} dest={{ bin_dir }}/{{ item }} mode=0755
Expand Down
6 changes: 5 additions & 1 deletion roles/kube-node/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,19 @@

- name: 创建kubelet的systemd unit文件
template: src=kubelet.service.j2 dest=/etc/systemd/system/kubelet.service
tags: kubelet-conf

- name: daemon-reload
shell: systemctl daemon-reload
shell: systemctl daemon-reload
tags: kubelet-conf

- name: enable-kubelet
shell: systemctl enable kubelet
tags: kubelet-conf

- name: start-kubelet
shell: systemctl restart kubelet
tags: kubelet-conf

- name: approve-kubelet-csr
shell: "sleep 15 && {{ bin_dir }}/kubectl get csr|grep 'Pending' | awk 'NR>0{print $1}'| xargs {{ bin_dir }}/kubectl certificate approve"
Expand Down
2 changes: 1 addition & 1 deletion roles/kube-node/templates/kubelet.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WorkingDirectory=/var/lib/kubelet
ExecStart={{ bin_dir }}/kubelet \
--address={{ NODE_IP }} \
--hostname-override={{ NODE_IP }} \
--pod-infra-container-image=harbor.tf56.lo/k8s/pod-infrastructure:latest \
--pod-infra-container-image=mirrorgooglecontainers/pause-amd64:3.0 \
--experimental-bootstrap-kubeconfig=/etc/kubernetes/bootstrap.kubeconfig \
--kubeconfig=/etc/kubernetes/kubelet.kubeconfig \
--cert-dir={{ ca_dir }} \
Expand Down
7 changes: 5 additions & 2 deletions roles/lb/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

- name: apt更新缓存刷新
apt: update_cache=yes cache_valid_time=72000

- name: 安装 haproxy
shell: "apt-get update && apt-get install haproxy -y"
apt: name=haproxy state=latest

- name: 创建haproxy配置目录
file: name=/etc/haproxy state=directory
Expand All @@ -9,7 +12,7 @@
template: src=haproxy.cfg.j2 dest=/etc/haproxy/haproxy.cfg

- name: 安装 keepalived
shell: "apt-get install keepalived -y"
apt: name=keepalived state=latest

- name: 创建keepalived配置目录
file: name=/etc/keepalived state=directory
Expand Down
1 change: 1 addition & 0 deletions roles/lb/templates/haproxy.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ listen kube-master
balance source
server s1 {{ LB_EP1 }} check inter 10000 fall 2 rise 2 weight 1
server s2 {{ LB_EP2 }} check inter 10000 fall 2 rise 2 weight 1
server s3 {{ LB_EP3 }} check inter 10000 fall 2 rise 2 weight 1
2 changes: 1 addition & 1 deletion roles/lb/templates/keepalived-backup.conf.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
global_defs {
router_id {{ LB_NAME }}
router_id lb-backup
}

vrrp_instance VI-kube-master {
Expand Down
2 changes: 1 addition & 1 deletion roles/lb/templates/keepalived-master.conf.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
global_defs {
router_id {{ LB_NAME }}
router_id lb-master
}

vrrp_script check-haproxy {
Expand Down

0 comments on commit 7a4cd9a

Please sign in to comment.