博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Kubernetes-v1.12.0基于kubeadm部署
阅读量:4549 次
发布时间:2019-06-08

本文共 12204 字,大约阅读时间需要 40 分钟。

1.主机规划

#master节点(etcd/apiserver/scheduler/controller manager) master.example.com eth0:  192.168.0.135 eth1:  192.168.1.53 #node1 node1.example.com eth0: 192.168.0.136 eth1: 192.168.1.54 #node2node2.example.com eth0: 192.168.0.137 eth1: 192.168.1.55

 

2.安装kubeadm

[root@master ~]# systemctl start docker

[root@master ~]# systemctl enable docker

yum install -y kubelet kubeadm kubectl kubernetes-cni systemctl enable kubelet && systemctl start kubelet

 

3.下载镜像并更新tag

#coding:utf8import osS_registry = 'registry.cn-hangzhou.aliyuncs.com/bubblelin/'D_registry = 'k8s.gcr.io/'master_image = ['kube-apiserver:v1.12.0','kube-controller-manager:v1.12.0',                'kube-scheduler:v1.12.0','kube-proxy:v1.12.0','pause:3.1',                'etcd:3.2.24','coredns:1.2.2']def PullImage(registry,images):    print("一共%s个镜像" %(len(images),))    index = 1    for image in images:        print("开始下载第[%d]个镜像 ---> [%s]" %(index,image))        cmd = "docker pull " + registry + image        os.system(cmd)        print("done!")        index +=1def TagImage(sregistry,dregistry,images):    print("一共%s个镜像" %(len(images),))    index = 1     for image in images:        print("开始tag第[%d]个镜像 ---> [%s]  --->[%s]" %(index,sregistry+image,dregistry+image))        cmd = "docker tag " + sregistry+image + " " +  dregistry + image        os.system(cmd)        print("done!")        index +=1if __name__ == '__main__':    #PullImage(S_registry,master_image)    TagImage(S_registry,D_registry,master_image)

4.初始化

[root@master ~]# kubeadm init --kubernetes-version=v1.12.0 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.0.135[init] using Kubernetes version: v1.12.0[preflight] running pre-flight checks	[WARNING Firewalld]: firewalld is active, please ensure ports [6443 10250] are open or your cluster may not function correctly	[WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service'[preflight/images] Pulling images required for setting up a Kubernetes cluster[preflight/images] This might take a minute or two, depending on the speed of your internet connection[preflight/images] You can also perform this action in beforehand using 'kubeadm config images pull'[kubelet] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"[kubelet] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"[preflight] Activating the kubelet service[certificates] Generated ca certificate and key.[certificates] Generated apiserver certificate and key.[certificates] apiserver serving cert is signed for DNS names [master.example.com kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.0.135][certificates] Generated apiserver-kubelet-client certificate and key.[certificates] Generated front-proxy-ca certificate and key.[certificates] Generated front-proxy-client certificate and key.[certificates] Generated etcd/ca certificate and key.[certificates] Generated etcd/healthcheck-client certificate and key.[certificates] Generated apiserver-etcd-client certificate and key.[certificates] Generated etcd/server certificate and key.[certificates] etcd/server serving cert is signed for DNS names [master.example.com localhost] and IPs [127.0.0.1 ::1][certificates] Generated etcd/peer certificate and key.[certificates] etcd/peer serving cert is signed for DNS names [master.example.com localhost] and IPs [192.168.0.135 127.0.0.1 ::1][certificates] valid certificates and keys now exist in "/etc/kubernetes/pki"[certificates] Generated sa key and public key.[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/admin.conf"[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/kubelet.conf"[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/controller-manager.conf"[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/scheduler.conf"[controlplane] wrote Static Pod manifest for component kube-apiserver to "/etc/kubernetes/manifests/kube-apiserver.yaml"[controlplane] wrote Static Pod manifest for component kube-controller-manager to "/etc/kubernetes/manifests/kube-controller-manager.yaml"[controlplane] wrote Static Pod manifest for component kube-scheduler to "/etc/kubernetes/manifests/kube-scheduler.yaml"[etcd] Wrote Static Pod manifest for a local etcd instance to "/etc/kubernetes/manifests/etcd.yaml"[init] waiting for the kubelet to boot up the control plane as Static Pods from directory "/etc/kubernetes/manifests" [init] this might take a minute or longer if the control plane images have to be pulled[apiclient] All control plane components are healthy after 40.010009 seconds[uploadconfig] storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace[kubelet] Creating a ConfigMap "kubelet-config-1.12" in namespace kube-system with the configuration for the kubelets in the cluster[markmaster] Marking the node master.example.com as master by adding the label "node-role.kubernetes.io/master=''"[markmaster] Marking the node master.example.com as master by adding the taints [node-role.kubernetes.io/master:NoSchedule][patchnode] Uploading the CRI Socket information "/var/run/dockershim.sock" to the Node API object "master.example.com" as an annotation[bootstraptoken] using token: 33x3h7.tejszerd0znwtjum[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-proxyYour 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/configYou 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 nodeas root:  kubeadm join 192.168.0.135:6443 --token 33x3h7.tejszerd0znwtjum --discovery-token-ca-cert-hash sha256:2d790600988cf71dda1a5f2ea2e798918acf54584ff3ffe1dca006ec8a4c80a6

 

5.验证 

[root@master ~]# export KUBECONFIG=/etc/kubernetes/admin.conf [root@master ~]# kubectl get nodesNAME                 STATUS     ROLES    AGE   VERSIONmaster.example.com   NotReady   master   11m   v1.12.3[root@master ~]# kubectl get pods --all-namespacesNAMESPACE     NAME                                         READY   STATUS    RESTARTS   AGEkube-system   coredns-576cbf47c7-6mvtt                     0/1     Pending   0          11mkube-system   coredns-576cbf47c7-djzgn                     0/1     Pending   0          11mkube-system   etcd-master.example.com                      1/1     Running   0          10mkube-system   kube-apiserver-master.example.com            1/1     Running   0          11mkube-system   kube-controller-manager-master.example.com   1/1     Running   0          10mkube-system   kube-proxy-wj62f                             1/1     Running   0          11mkube-system   kube-scheduler-master.example.com            1/1     Running   0          11m

 

6.网络配置

wget https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml docker pull registry.cn-hangzhou.aliyuncs.com/kubernetes1112images/flannel:v0.10.0-amd64
docker tag registry.cn-hangzhou.aliyuncs.com/kubernetes_containers/flannel:v0.10.0-amd64 quay.io/coreos/flannel:v0.10.0-amd64
[root@master ~]# vim kube-flannel.yml      containers:      - name: kube-flannel        image: quay.io/coreos/flannel:v0.10.0-amd64        command:        - /opt/bin/flanneld        args:        - --ip-masq        - --kube-subnet-mgr        - --iface=ens33   #指定网卡[root@master ~]# kubectl apply -f kube-flannel.yml

 

7.添加节点

下载镜像

#coding:utf8import osS_registry = 'registry.cn-hangzhou.aliyuncs.com/bubblelin/'D_registry = 'k8s.gcr.io/'node_image = [ 'kube-proxy:v1.12.0','pause:3.1',]def PullImage(registry,images):    print("一共%s个镜像" %(len(images),))    index = 1    for image in images:        print("开始下载第[%d]个镜像 ---> [%s]" %(index,image))        cmd = "docker pull " + registry + image        os.system(cmd)        print("done!")        index +=1def TagImage(sregistry,dregistry,images):    print("一共%s个镜像" %(len(images),))    index = 1    for image in images:        print("开始tag第[%d]个镜像 ---> [%s]  --->[%s]" %(index,sregistry+image,dregistry+image))        cmd = "docker tag " + sregistry+image + " " +  dregistry + image        os.system(cmd)        print("done!")        index +=1if __name__ == '__main__':    PullImage(S_registry,node_image)    TagImage(S_registry,D_registry,node_image)

2.kubeadm添加

[root@node1 ~]# kubeadm join 192.168.0.135:6443 --token 33x3h7.tejszerd0znwtjum --discovery-token-ca-cert-hash sha256:2d790600988cf71dda1a5f2ea2e798918acf54584ff3ffe1dca006ec8a4c80a6[preflight] running pre-flight checks    [WARNING RequiredIPVSKernelModulesAvailable]: the IPVS proxier will not be used, because the following required kernel modules are not loaded: [ip_vs_wrr ip_vs_sh ip_vs ip_vs_rr] or no builtin kernel ipvs support: map[ip_vs:{} ip_vs_rr:{} ip_vs_wrr:{} ip_vs_sh:{} nf_conntrack_ipv4:{}]you can solve this problem with following methods: 1. Run 'modprobe -- ' to load missing kernel modules;2. Provide the missing builtin kernel ipvs support    [WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service'[discovery] Trying to connect to API Server "192.168.0.135:6443"[discovery] Created cluster-info discovery client, requesting info from "https://192.168.0.135:6443"[discovery] Requesting info from "https://192.168.0.135: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 "192.168.0.135:6443"[discovery] Successfully established connection with API Server "192.168.0.135:6443"[kubelet] Downloading configuration for the kubelet from the "kubelet-config-1.12" ConfigMap in the kube-system namespace[kubelet] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"[kubelet] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"[preflight] 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 "node1.example.com" as an annotationThis node has joined the cluster:* Certificate signing request was sent to apiserver and a response was received.* The Kubelet was informed of the new secure connection details.Run 'kubectl get nodes' on the master to see this node join the cluster.

 

 

8.FAQ

1.发现coredns出现问题,pod状态一直是pendding状态。

kubectl descripe pod xxxx -n kube-system

Warning  FailedScheduling  21m (x243 over 61m)   default-scheduler  0/1 nodes are available: 1 node(s) had taints that the pod didn't tolerate.  Warning  FailedScheduling  4m47s (x61 over 14m)  default-scheduler  0/1 nodes are available: 1 node(s) had taints that the pod didn't tolerate.

正常: 百度taints 污点,应为没有添加node节点导致。 默认不会给master节点分配pod。

[root@master ~]# kubectl describe node master.example.com |grep -E '(Roles|Taints)'Roles:              masterTaints:             node-role.kubernetes.io/master:NoSchedule

 

2.防火墙问题

经过telnet 发现no route tohost  。 关闭防火墙即可。

info: dial tcp 192.168.0.135:6443: connect: no route to host][discovery] Failed to request cluster info, will try again: [Get https://192.168.0.135:6443/api/v1/namespaces/kube-public/configmaps/cluster-info: dial tcp 192.168.0.135:6443: connect: no route to host]

 

参考链接:https://www.cnblogs.com/cocowool/p/kubeadm_install_kubernetes.html

转载于:https://www.cnblogs.com/mascot1/p/10048692.html

你可能感兴趣的文章
ASP.NET Development Server使用方法
查看>>
服务器运维基础指南
查看>>
读后感
查看>>
使用Crypto对数据进行加密解密
查看>>
CSS五類常用選擇器(收藏)
查看>>
have a thing用法
查看>>
为什么 远程钩子 必须使用动态链接库dll(而且是.data? 段共享的动态链接库)...
查看>>
redis 从0到1 linux下的安装使用 数据类型 以及操作指令 一
查看>>
MongoDB-启动的时候出现了问题
查看>>
解决nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed错误
查看>>
第三次作
查看>>
模板 - ST表
查看>>
ZMQ示例:使用 curve 进行加密通信
查看>>
【网络流】 SGU 194 Reactor Cooling 无源无汇上下界可行流(裸题)
查看>>
cmd命令大全
查看>>
SSM框架---详细整合教程
查看>>
hdu 1907 尼姆博弈
查看>>
hdu 2177 威佐夫博弈变形
查看>>
面试问题联想
查看>>
IOS数据持久化之归档NSKeyedArchiver
查看>>