首页 > 代码库 > kubernetes 1.4.5集群部署

kubernetes 1.4.5集群部署

2016/11/16 23:39:58

环境: centos7
  1. [fu@centos server]$ uname -a
  2. Linux centos 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


1. 初始化环境

关闭防火墙:
  1. [root@k8s-master fu]# systemctl stop firewalld
  2. [root@k8s-master fu]# systemctl disable firewalld

1.1 环境:

节点IP
node-1192.168.44.129
node-2192.168.44.131
node-3192.168.44.132

1.2 设置hostname

hostnamectl --static set-hostname hostname
IPhostname
192.168.44.129k8s-master
192.168.44.131k8s-node-1
192.168.44.132k8s-node-2

master:
  1. [root@centos fu]# hostnamectl --static set-hostname k8s-master
node-1
  1. [root@centos fu]# hostnamectl --static set-hostname k8s-node-1
node-2
  1. [root@centos fu]# hostnamectl --static set-hostname k8s-node-2

1.3 配置 hosts

  1. vi /etc/hosts

IPhostname
192.168.44.129 k8s-master
192.168.44.131 k8s-node-1
192.168.44.132 k8s-node-2

分别在hosts中加入:
  1. 192.168.44.129 k8s-master
  2. 192.168.44.131 k8s-node-1
  3. 192.168.44.132 k8s-node-2

或者,直接执行,在hosts中追加:
  1. echo 192.168.44.129 k8s-master
  2. 192.168.44.131 k8s-node-1
  3. 192.168.44.132 k8s-node-2‘ >> /etc/hosts

1.4安装kubelet 和kubeadm

添加yum  (注:root用户下执行)

  1. cat <<EOF > /etc/yum.repos.d/k8s.repo
  2. [kubelet]
  3. name=kubelet
  4. baseurl=http://files.rm-rf.ca/rpms/kubelet/
  5. enabled=1
  6. gpgcheck=0
  7. EOF
安装并启动:
  1. yum install docker kubelet kubeadm kubectl kubernetes-cni
  2. systemctl enable docker && systemctl start docker
  3. systemctl enable kubelet && systemctl start kubelet

2 部署 kubernetes master

2.1 添加yum(如环境统一处理,此处略过)

注:root用户下执行
  1. cat <<EOF> /etc/yum.repos.d/k8s.repo
  2. [kubelet]
  3. name=kubelet
  4. baseurl=http://files.rm-rf.ca/rpms/kubelet/
  5. enabled=1
  6. gpgcheck=0
  7. EOF

安装 kubernetes依赖环境:
yum有很多源,大多是网络上的。makecache建立一个缓存,以后用install安装软件时就在缓存中搜索,提高了速度。
  1. [root@k8s-master fu]# yum makecache
  2. [root@k8s-master fu]# yum install -y socat kubelet kubeadm kubectl kubernetes-cni
技术分享
技术分享
 

2.2 安装docker

  1. wget -qO- https://get.docker.com/ | sh
如果提示:
  1. bash: wget: 未找到命令
则先安装wget:
  1. [root@centos fu]# yum -y install wget
如果已经安装过dokcer则可直接启动:
提示未启动:
  1. [root@centos fu]# docker images
  2. Cannot connect to the Docker daemon. Is the docker daemon running on this host?

技术分享
 
docker设为开机启动并启动:
  1. systemctl enable docker
  2. systemctl start docker

2.3 下载镜像

  1. images=(kube-proxy-amd64:v1.4.5 kube-discovery-amd64:1.0 kubedns-amd64:1.7 kube-scheduler-amd64:v1.4.5 kube-controller-manager-amd64:v1.4.5 kube-apiserver-amd64:v1.4.5 etcd-amd64:2.2.5 kube-dnsmasq-amd64:1.3 exechealthz-amd64:1.1 pause-amd64:3.0 kubernetes-dashboard-amd64:v1.4.1)
  2. for imageName in ${images[@]} ; do
  3. docker pull jicki/$imageName
  4. docker tag jicki/$imageName gcr.io/google_containers/$imageName
  5. docker rmi jicki/$imageName
  6. done

2.4 启动 kubernetes

  1. systemctl enable kubelet
  2. systemctl start kubelet

2.5 创建集群

  1. kubeadm init --api-advertise-addresses=192.168.44.129 --use-kubernetes-version v1.4.5

如提示:

  1. Running pre-flight checks
  2. preflight check errors:
  3. /etc/kubernetes is not empty

则:
  1. [root@k8s-master kubernetes]# rm -rf manifests/
然后再执行 init

2.6 记录 token

init打出的日志,把加入集群的token记录下来。
  1. Kubernetes master initialised successfully!
  2. You can now join any number of machines by running the following on each node:

  3. kubeadm join --token=a46536.cad65192491d2fd9 192.168.44.129

2.7 检查 kubelet 状态

  1. systemctl status kubelet
技术分享
 
2.8 查询集群pods:
  1. [root@k8s-master system]# kubectl get nodes
技术分享
 

3 部署 kubernetes node

3.1 安装docker

  1. wget -qO- https://get.docker.com/ | sh
如果提示:
  1. bash: wget: 未找到命令
则先安装wget:
  1. [root@centos fu]# yum -y install wget
设置docker开机启动并启动:
  1. systemctl enable docker
  2. systemctl start docker

3.2 下载镜像

  1. images=(kube-proxy-amd64:v1.4.5 kube-discovery-amd64:1.0 kubedns-amd64:1.7 kube-scheduler-amd64:v1.4.5 kube-controller-manager-amd64:v1.4.5 kube-apiserver-amd64:v1.4.5 etcd-amd64:2.2.5 kube-dnsmasq-amd64:1.3 exechealthz-amd64:1.1 pause-amd64:3.0 kubernetes-dashboard-amd64:v1.4.1)
  2. for imageName in ${images[@]} ; do
  3. docker pull jicki/$imageName
  4. docker tag jicki/$imageName gcr.io/google_containers/$imageName
  5. docker rmi jicki/$imageName
  6. done

3.3 安装并启动 kubernetes(如环境统一处理,此处略过)

可以按上面先指定yum源,速度会有提升
  1. yum makecache
  2. yum install -y socat kubelet kubeadm kubectl kubernetes-cni

  1. systemctl enable kubelet
  2. systemctl start kubelet

3.4 加入集群

复制自己master创建集群的返回值
  1. kubeadm join --token=a46536.cad65192491d2fd9 192.168.44.129
返回如下错误,须手动清空该目录
技术分享
 
如果此错误,请查看防火墙或selinux
技术分享
 
返回:
技术分享
 


都加入成功后,通过get nodes查看集群状态:
技术分享
 
重启机器会有延迟:
技术分享
 

4 设置 kubernetes

  1. kubectl apply -f https://git.io/weave-kube
  2. daemonset "weave-net" created

4.2 查看系统服务状态

  1. # kube-dns 必须配置完网络才能 Running
  2. [root@k8s-master ~]#kubectl get pods --all-namespaces
  3. NAMESPACE NAME READY STATUS RESTARTS AGE
  4. kube-system dummy-2088944543-io6ca 1/1 Running 0 22m
  5. kube-system etcd-k8s-master 1/1 Running 0 22m
  6. kube-system kube-apiserver-k8s-master 1/1 Running 0 22m
  7. kube-system kube-controller-manager-k8s-master 1/1 Running 0 20m
  8. kube-system kube-discovery-982812725-rm6ut 1/1 Running 0 22m
  9. kube-system kube-dns-2247936740-htw22 3/3 Running 0 21m
  10. kube-system kube-proxy-amd64-lo0hr 1/1 Running 0 15m
  11. kube-system kube-proxy-amd64-t3qpn 1/1 Running 0 15m
  12. kube-system kube-proxy-amd64-wwj2z 1/1 Running 0 21m
  13. kube-system kube-scheduler-k8s-master 1/1 Running 0 21m
  14. kube-system weave-net-6k3ha 2/2 Running 0 11m
  15. kube-system weave-net-auf0c 2/2 Running 0 11m
  16. kube-system weave-net-bxj6d 2/2 Running 0 11m









4.3 其他主机控制集群

# 备份master节点的 配置文件

/etc/kubernetes/admin.conf

# 保存至 其他电脑, 通过执行配置文件控制集群

kubectl --kubeconfig ./admin.conf get nodes

4.4 配置dashboard

#下载 yaml 文件, 直接导入会去官方拉取images

curl -O https://rawgit.com/kubernetes/dashboard/master/src/deploy/kubernetes-dashboard.yaml


#编辑 yaml 文件

vi kubernetes-dashboard.yaml

image: gcr.io/google_containers/kubernetes-dashboard-amd64:v1.4.0

修改为

image: gcr.io/google_containers/kubernetes-dashboard-amd64:v1.4.1


imagePullPolicy: Always

修改为

imagePullPolicy: IfNotPresent

kubectl create -f ./kubernetes-dashboard.yaml

deployment "kubernetes-dashboard" created
service "kubernetes-dashboard" created
# 查看 NodePort ,既外网访问端口

kubectl describe svc kubernetes-dashboard --namespace=kube-system

NodePort:               <unset> 31736/TCP

# 访问 dashboard

http://10.6.0.140:31736

技术分享

FAQ:

kube-discovery error

	failed to create "kube-discovery" deployment [deployments.extensions "kube-discovery" already exists]
	

systemctl stop kubelet;
docker rm -f -v $(docker ps -q);
find /var/lib/kubelet | xargs -n 1 findmnt -n -t tmpfs -o TARGET -T | uniq | xargs -r umount -v;
rm -r -f /etc/kubernetes /var/lib/kubelet /var/lib/etcd;

systemctl start kubelet

kubeadm init

来源: http://www.xf80.com/2016/10/31/kubernetes-update-1.4.5/#section-8











****博客:https://mritd.me/2016/10/29/set-up-kubernetes-cluster-by-kubeadm/




























github上,kubernetes版本:https://github.com/kubernetes/kubernetes/releases
技术分享
 


来自为知笔记(Wiz)


kubernetes 1.4.5集群部署