kubeadm之ha (1)

  • master 節(jié)點(diǎn) (高可用)
    kube-apiserver: 無狀態(tài),直接前面掛負(fù)載均衡
    kube-controller-manager: 有狀態(tài)径玖,集群只能有一個(gè)負(fù)責(zé)處理事務(wù)榕茧,通過選舉leader的方式實(shí)現(xiàn)高可用(三臺)
    kube-scheduler: 有狀態(tài)奴紧,同kube-controller-manager(三臺)

  • etcd
    基于raft算法實(shí)現(xiàn)數(shù)據(jù)存儲(chǔ)高可用 (三臺)

  • worker節(jié)點(diǎn)
    基于多個(gè)worker節(jié)點(diǎn)實(shí)現(xiàn)業(yè)務(wù)高可用搪花,無需額外設(shè)置

集群自帶etcd高可用部署,參考 https://kubernetes.io/docs/setup/independent/high-availability/

1. 三個(gè)節(jié)點(diǎn)分別安裝kubeadm,kubelet

root@master-192:/etc/apt# apt-get install kubeadm kubelet
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹       
正在讀取狀態(tài)信息... 完成       

root@master-192:/etc/apt# dpkg -l|grep kube
ii  kubeadm                              1.13.1-00                                  amd64        Kubernetes Cluster Bootstrapping Tool
ii  kubectl                              1.13.1-00                                  amd64        Kubernetes Command Line Tool
ii  kubelet                              1.13.1-00                                  amd64        Kubernetes Node Agent
ii  kubernetes-cni                       0.6.0-00                                   amd64        Kubernetes CNI

修改kubelet參數(shù)

root@master-192:/etc/apt# vi /etc/systemd/system/kubelet.service.d/10-kubeadm.conf 
...
Environment="KUBELET_POD_INFRA_CONTAINER=--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.0"

ExecStart=/usr/bin/kubelet $KUBELET_POD_INFRA_CONTAINER $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS

設(shè)置kubelet開機(jī)啟動(dòng)

root@master-192:/etc/apt# systemctl daemon-reload
root@master-192:/etc/apt# systemctl enable kubelet

2.配置haproxy


#---------------my k8s proxy--------------------

...
listen k8s_admin[root@localhost ~]# cat /etc/haproxy/haproxy.cfg 
#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------


    bind 172.30.81.199:6443
    mode tcp
    server node194 172.30.81.194:6443
    server node193 172.30.81.193:6443
    server node192 172.30.81.192:6443

啟動(dòng)haproxy

[root@localhost ~]# netstat -antp|grep 6443
tcp        0      0 172.30.81.199:6443      0.0.0.0:*               LISTEN      1630/haproxy        

3.初始集群

root@master-194:/etc/apt/sources.list.d# cat /root/ha/kubeadm.conf 
apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
kubernetesVersion: v1.13.0
apiServer:
  certSANs:
  - "172.30.81.199"
controlPlaneEndpoint: "172.30.81.199:6443"
networking:
  dnsDomain: cluster.local
  podSubnet: "192.168.0.0/16"
  serviceSubnet: 10.96.0.0/12
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers
root@master-194:/etc/apt/sources.list.d# kubeadm init --config /root/ha/kubeadm.conf 
[init] Using Kubernetes version: v1.13.0
[preflight] Running pre-flight checks
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Activating the kubelet service
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [master-194 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 172.30.81.194 172.30.81.199 172.30.81.199]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [master-194 localhost] and IPs [172.30.81.194 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [master-194 localhost] and IPs [172.30.81.194 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[apiclient] All control plane components are healthy after 23.012330 seconds
[uploadconfig] storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.13" in namespace kube-system with the configuration for the kubelets in the cluster
[patchnode] Uploading the CRI Socket information "/var/run/dockershim.sock" to the Node API object "master-194" as an annotation
[mark-control-plane] Marking the node master-194 as control-plane by adding the label "node-role.kubernetes.io/master=''"
[mark-control-plane] Marking the node master-194 as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: so9886.5lxjilqqrkl1d2z0
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstraptoken] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstraptoken] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstraptoken] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstraptoken] creating the "cluster-info" ConfigMap in the "kube-public" namespace
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy

Your Kubernetes master has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of machines by running the following on each node
as root:

  kubeadm join 172.30.81.199:6443 --token so9886.5lxjilqqrkl1d2z0 --discovery-token-ca-cert-hash sha256:bbcddbf66dbefeb645598614e28c1557fb04fb4fbd288b36edc18816250f9e77

查看節(jié)點(diǎn)情況

root@master-194:/etc/apt/sources.list.d# kubectl get nodes
NAME         STATUS     ROLES    AGE   VERSION
master-194   NotReady   master   81s   v1.13.1

root@master-194:/etc/apt/sources.list.d# kubectl get po -n kube-system 
NAME                                 READY   STATUS    RESTARTS   AGE
coredns-89cc84847-hznhd              0/1     Pending   0          88s
coredns-89cc84847-r2w2g              0/1     Pending   0          88s
etcd-master-194                      1/1     Running   0          52s
kube-apiserver-master-194            1/1     Running   0          46s
kube-controller-manager-master-194   1/1     Running   0          39s
kube-proxy-72844                     1/1     Running   0          88s
kube-scheduler-master-194            1/1     Running   0          36s

初始化網(wǎng)絡(luò)

下載地址 https://github.com/xiaotech/calico

root@master-194:~/adds/calico# kubectl create -f .
configmap/calico-config created
secret/calico-etcd-secrets created
daemonset.extensions/calico-node created
serviceaccount/calico-node created
deployment.extensions/calico-kube-controllers created
serviceaccount/calico-kube-controllers created
daemonset.extensions/calico-etcd created
service/calico-etcd created
clusterrole.rbac.authorization.k8s.io/calico-kube-controllers created
clusterrolebinding.rbac.authorization.k8s.io/calico-kube-controllers created
clusterrole.rbac.authorization.k8s.io/calico-node created
clusterrolebinding.rbac.authorization.k8s.io/calico-node cr

網(wǎng)絡(luò)部署完成后薯嗤,查看狀態(tài)

root@master-194:~/adds/calico# kubectl get nodes
NAME         STATUS   ROLES    AGE     VERSION
master-194   Ready    master   8m38s   v1.13.1
root@master-194:~/adds/calico# kubectl get po -n kube-system
NAME                                       READY   STATUS    RESTARTS   AGE
calico-etcd-dfzht                          1/1     Running   0          6m7s
calico-kube-controllers-7df47b8cbc-dnq4l   1/1     Running   0          6m15s
calico-node-8gqw2                          2/2     Running   1          6m15s
coredns-89cc84847-hznhd                    1/1     Running   0          8m27s
coredns-89cc84847-r2w2g                    1/1     Running   0          8m27s
etcd-master-194                            1/1     Running   0          7m51s
kube-apiserver-master-194                  1/1     Running   0          7m45s
kube-controller-manager-master-194         1/1     Running   0          7m38s
kube-proxy-72844                           1/1     Running   0          8m27s
kube-scheduler-master-194                  1/1     Running   0          7m35s

4.其余master節(jié)點(diǎn)的加入

首先拷貝證書文件到其他節(jié)點(diǎn)

master_nodes="172.30.81.192 172.30.81.193"
for i in $master_nodes
do
    ssh $i mkdir /etc/kubernetes/pki/etcd -p
    scp /etc/kubernetes/pki/ca.crt ${i}:/etc/kubernetes/pki/
    scp /etc/kubernetes/pki/ca.key ${i}:/etc/kubernetes/pki/
    scp /etc/kubernetes/pki/sa.key ${i}:/etc/kubernetes/pki/
    scp /etc/kubernetes/pki/sa.pub ${i}:/etc/kubernetes/pki/
    scp /etc/kubernetes/pki/front-proxy-ca.crt ${i}:/etc/kubernetes/pki/
    scp /etc/kubernetes/pki/front-proxy-ca.key ${i}:/etc/kubernetes/pki/
    scp /etc/kubernetes/pki/etcd/ca.crt ${i}:/etc/kubernetes/pki/etcd/
    scp /etc/kubernetes/pki/etcd/ca.key ${i}:/etc/kubernetes/pki/etcd/
    scp /etc/kubernetes/admin.conf ${i}:/etc/kubernetes/
done

join節(jié)點(diǎn)

root@master-193:~# kubeadm join 172.30.81.199:6443 --token so9886.5lxjilqqrkl1d2z0 --discovery-token-ca-cert-hash sha256:bbcddbf66dbefeb645598614e28c1557fb04fb4fbd288b36edc18816250f9e77 --experimental-control-plane
[preflight] Running pre-flight checks
    [WARNING Hostname]: hostname "master-193" could not be reached
    [WARNING Hostname]: hostname "master-193": lookup master-193 on 114.114.114.114:53: no such host
[discovery] Trying to connect to API Server "172.30.81.199:6443"
[discovery] Created cluster-info discovery client, requesting info from "https://172.30.81.199:6443"
[discovery] Requesting info from "https://172.30.81.199:6443" again to validate TLS against the pinned public key
[discovery] Cluster info signature and contents are valid and TLS certificate validates against pinned roots, will use API Server "172.30.81.199:6443"
[discovery] Successfully established connection with API Server "172.30.81.199:6443"
[join] Reading configuration from the cluster...
[join] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[join] Running pre-flight checks before initializing the new control plane instance
    [WARNING Hostname]: hostname "master-193" could not be reached
    [WARNING Hostname]: hostname "master-193": lookup master-193 on 114.114.114.114:53: no such host
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [master-193 localhost] and IPs [172.30.81.193 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [master-193 localhost] and IPs [172.30.81.193 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [master-193 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 172.30.81.193 172.30.81.199 172.30.81.199]
[certs] Generating "front-proxy-client" certificate and key
[certs] valid certificates and keys now exist in "/etc/kubernetes/pki"
[certs] Using the existing "sa" key
[kubeconfig] Using existing up-to-date kubeconfig file: "/etc/kubernetes/admin.conf"
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[etcd] Checking Etcd cluster health
[kubelet] Downloading configuration for the kubelet from the "kubelet-config-1.13" ConfigMap in the kube-system namespace
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Activating the kubelet service
[tlsbootstrap] Waiting for the kubelet to perform the TLS Bootstrap...
[patchnode] Uploading the CRI Socket information "/var/run/dockershim.sock" to the Node API object "master-193" as an annotation
[etcd] Announced new etcd member joining to the existing etcd cluster
[etcd] Wrote Static Pod manifest for a local etcd instance to "/etc/kubernetes/manifests/etcd.yaml"
[uploadconfig] storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[mark-control-plane] Marking the node master-193 as control-plane by adding the label "node-role.kubernetes.io/master=''"
[mark-control-plane] Marking the node master-193 as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]

This node has joined the cluster and a new control plane instance was created:

* Certificate signing request was sent to apiserver and approval was received.
* The Kubelet was informed of the new secure connection details.
* Master label and taint were applied to the new node.
* The Kubernetes control plane instances scaled up.
* A new etcd member was added to the local/stacked etcd cluster.

To start administering your cluster from this node, you need to run the following as a regular user:

    mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config

Run 'kubectl get nodes' to see this node join the cluster.

查看節(jié)點(diǎn)情況

root@master-194:/home# kubectl get nodes
NAME         STATUS   ROLES    AGE     VERSION
master-192   Ready    master   2m32s   v1.13.1
master-193   Ready    master   4m49s   v1.13.1
master-194   Ready    master   24m     v1.13.1


root@master-194:/home# kubectl get pod -n kube-system
NAME                                       READY   STATUS    RESTARTS   AGE
calico-etcd-72cfp                          1/1     Running   0          22s
calico-etcd-dfzht                          1/1     Running   0          21m
calico-etcd-ptzz4                          1/1     Running   0          4m25s
calico-kube-controllers-7df47b8cbc-dnq4l   1/1     Running   0          22m
calico-node-46hc6                          2/2     Running   2          5m11s
calico-node-6qczp                          2/2     Running   0          2m54s
calico-node-8gqw2                          2/2     Running   1          22m
coredns-89cc84847-hznhd                    1/1     Running   0          24m
coredns-89cc84847-r2w2g                    1/1     Running   0          24m
etcd-master-192                            1/1     Running   1          2m52s
etcd-master-193                            1/1     Running   0          5m10s
etcd-master-194                            1/1     Running   0          23m
kube-apiserver-master-192                  1/1     Running   2          2m53s
kube-apiserver-master-193                  1/1     Running   0          5m10s
kube-apiserver-master-194                  1/1     Running   0          23m
kube-controller-manager-master-192         1/1     Running   2          2m53s
kube-controller-manager-master-193         1/1     Running   0          5m10s
kube-controller-manager-master-194         1/1     Running   1          23m
kube-proxy-2t6r4                           1/1     Running   0          5m11s
kube-proxy-72844                           1/1     Running   0          24m
kube-proxy-vjr8k                           1/1     Running   1          2m54s
kube-scheduler-master-192                  1/1     Running   2          2m53s
kube-scheduler-master-193                  1/1     Running   0          5m10s
kube-scheduler-master-194                  1/1     Running   1          23m
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末顽爹,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子骆姐,更是在濱河造成了極大的恐慌镜粤,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,525評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件玻褪,死亡現(xiàn)場離奇詭異肉渴,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)带射,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,203評論 3 395
  • 文/潘曉璐 我一進(jìn)店門同规,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人窟社,你說我怎么就攤上這事券勺。” “怎么了灿里?”我有些...
    開封第一講書人閱讀 164,862評論 0 354
  • 文/不壞的土叔 我叫張陵关炼,是天一觀的道長。 經(jīng)常有香客問我匣吊,道長儒拂,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,728評論 1 294
  • 正文 為了忘掉前任色鸳,我火速辦了婚禮社痛,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘命雀。我一直安慰自己蒜哀,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,743評論 6 392
  • 文/花漫 我一把揭開白布咏雌。 她就那樣靜靜地躺著凡怎,像睡著了一般校焦。 火紅的嫁衣襯著肌膚如雪赊抖。 梳的紋絲不亂的頭發(fā)上统倒,一...
    開封第一講書人閱讀 51,590評論 1 305
  • 那天,我揣著相機(jī)與錄音迄委,去河邊找鬼翩隧。 笑死酌伊,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的浴鸿。 我是一名探鬼主播,決...
    沈念sama閱讀 40,330評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼弦追,長吁一口氣:“原來是場噩夢啊……” “哼岳链!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起劲件,我...
    開封第一講書人閱讀 39,244評論 0 276
  • 序言:老撾萬榮一對情侶失蹤掸哑,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后零远,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體苗分,經(jīng)...
    沈念sama閱讀 45,693評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,885評論 3 336
  • 正文 我和宋清朗相戀三年牵辣,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了摔癣。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,001評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡纬向,死狀恐怖择浊,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情逾条,我是刑警寧澤近她,帶...
    沈念sama閱讀 35,723評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站膳帕,受9級特大地震影響粘捎,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜危彩,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,343評論 3 330
  • 文/蒙蒙 一攒磨、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧汤徽,春花似錦娩缰、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,919評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽浮毯。三九已至,卻和暖如春泰鸡,著一層夾襖步出監(jiān)牢的瞬間债蓝,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,042評論 1 270
  • 我被黑心中介騙來泰國打工盛龄, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留饰迹,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,191評論 3 370
  • 正文 我出身青樓余舶,卻偏偏與公主長得像啊鸭,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子匿值,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,955評論 2 355

推薦閱讀更多精彩內(nèi)容