标签:manager err 指定 使用 配置环境 bind 加入集群 克隆虚拟机 join
本文主要参考https://blog.51cto.com/3241766/2405624,用于记录成功部署的过程
环境情况:
主机名 | 操作系统 | 主机ip地址 |
master | CentOS Linux release 7.2.1511 | 192.168.110.11 |
node2 | CentOS Linux release 7.2.1511 | 192.168.110.22 |
node3 | CentOS Linux release 7.2.1511 | 192.168.110.33 |
前言:
本文通过kudeadm方式在centos7.2上安装kubernetes v1.14.2集群,分为六个部分操作:
一、Docker安装
所有节点都需要安装docker
[root@centos7 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@centos7 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
docker的安装版本选择为18.09.6,这个版本安装是成功的
[root@centos7 ~]# yum install docker-ce-18.09.6 docker-ce-cli-18.09.6 containerd.io -y
[root@centos7 ~]# systemctl start docker
[root@centos7 ~]# systemctl enable docker
安装命令补全包,用于命令行操作时双击tab,自动提示
[root@centos7 ~]# yum -y install bash-completion && source /etc/profile.d/bash_completion.sh
docker默认的镜像源下载速度较慢,配置国内的aliyun镜像网站,加快镜像下载的速度
[root@centos7 ~]# mkdir -p /etc/docker [root@centos7 ~]# tee /etc/docker/daemon.json <<-‘EOF‘ { "registry-mirrors": ["https://v16stybc.mirror.aliyuncs.com"] } EOF
配置完成后,需要重新加载文件,并重启docker服务
[root@centos7 ~]# systemctl daemon-reload
[root@centos7 ~]# systemctl restart docker
[root@centos7 ~]# docker --version Docker version 18.09.6, build 481bc77156
安装的centos是已经禁用了防火墙(firewalld)和selinux,配置了阿里云的yum源;master和node节点都需要执行本部分操作内容。
更改主机名,此处更改的是master节点,其他node类似修改
[root@centos7 ~]# hostnamectl set-hostname master
修改/etc/hosts文件
[root@master ~]# cat >> /etc/hosts << EOF 192.168.110.11 master 192.168.110.22 node2 192.168.110.33 node3 EOF
要求mac地址和uuid号不同,在使用克隆虚拟机测试部署时,需要注意对比; 保证各节点mac和uuid唯一
[root@master ~]# cat /sys/class/net/ens33/address [root@master ~]# cat /sys/class/dmi/id/product_uuid
[root@master ~]# swapoff -a && sed -i.bak ‘/swap/s/^/#/‘ /etc/fstab
[root@master ~]# cat <<EOF > /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF [root@master ~]# sysctl -p /etc/sysctl.d/k8s.conf
修改daemon.json,新增‘"exec-opts": ["native.cgroupdriver=systemd"’
[root@master ~]# more /etc/docker/daemon.json { "registry-mirrors": ["https://v16stybc.mirror.aliyuncs.com"], "exec-opts": ["native.cgroupdriver=systemd"] }
加载文件,重启docker生效
[root@master ~]# systemctl daemon-reload && systemctl restart docker
修改cgroupdriver是为了消除告警:
[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
新增k8s.repo文件
[root@master ~]# cat <<EOF > /etc/yum.repos.d/k8s.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
节点重新生成缓存
[root@master ~]# yum clean all && yum -y makecache
本次安装的kubernetes版本为1.14.2,需要先检查源中是否包含这个版本
[root@master ~]# yum list kubelet --showduplicates | grep 1.14.2 kubelet.x86_64 1.14.2-0 kubernetes
安装三个软件包,分别为kubelet,kubeadm,kubectl
[root@master ~]# yum install -y kubelet-1.14.2 kubeadm-1.14.2 kubectl-1.14.2
启动服务,并设置开机自启
[root@master ~]# systemctl enable kubelet && systemctl start kubelet
设置自动补全
Kubernetes几乎所有的安装组件和Docker镜像都放在goolge自己的网站上,直接访问可能会有网络问题,这里的解决办法是从阿里云镜像仓库下载镜像,拉取到本地以后改回默认的镜像tag,脚本如下; 在节点上执行该脚本
[root@master ~]# more image.sh #!/bin/bash url=registry.cn-hangzhou.aliyuncs.com/google_containers version=v1.14.2 images=(`kubeadm config images list --kubernetes-version=$version|awk -F ‘/‘ ‘{print $2}‘`) for imagename in ${images[@]} ; do docker pull $url/$imagename docker tag $url/$imagename k8s.gcr.io/$imagename docker rmi -f $url/$imagename done
[root@master ~]# kubeadm init --apiserver-advertise-address 192.168.110.11 --pod-network-cidr=10.244.0.0/16
apiserver-advertise-address指定master的interface,pod-network-cidr指定Pod网络的范围,这里使用flannel网络方案。
将命令输出结果的最后一行保存下来,用于其他节点加入该集群,内容类似如下:
[root@master config]# more join_cluster kubeadm join 192.168.110.11:6443 --token z562f4.rs3yvzplnh3o80zn --discovery-token-ca-cert-hash sha256:1661c4532d4054a3f312a8f1e2232ef0b19033482aa52ca4e97f574b139e1cf7
配置环境变量
[root@master ~]# echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile [root@master ~]# source .bash_profile
本文所有操作都在root用户下执行,若为非root用户,则执行如下操作:
mkdir -p $HOME/.kube cp -i /etc/kubernetes/admin.conf $HOME/.kube/config chown $(id -u):$(id -g) $HOME/.kube/config
[root@master ~]# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
6. master节点配置
默认情况下集群不会在master上调度pod,如果偏想在master上调度Pod,可以执行如下操作:
查看污点:
[root@master ~]# kubectl describe node master|grep -i taints Taints: node-role.kubernetes.io/master:NoSchedule
删除默认污点:
[root@master ~]# kubectl taint nodes master node-role.kubernetes.io/master-
node/master untainted
同master节点
同master节点
在各个node上执行之前保存的join_cluster的命令
[root@master config]# kubeadm join 192.168.110.11:6443 --token z562f4.rs3yvzplnh3o80zn --discovery-token-ca-cert-hash sha256:1661c4532d4054a3f312a8f1e2232ef0b19033482aa52ca4e97f574b139e1cf7
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.1/aio/deploy/recommended.yaml
2. 配置本地访问dashboard
参照内容: https://github.com/kubernetes/dashboard
master节点执行命令,在master节点能够访问控制台,放在后台执行
[root@master ~]# kubectl proxy &
配置转发(可以做多层转发),在本地(这里是笔记本电脑)访问dashboard
$ ssh -L 8001:127.0.0.1:8001 -N -f root@192.168.110.11
笔记本是ubuntu系统,直接在命令行执行以上命令,转发master节点的8001端口
-L: 开启端口转发; local_socket(8001):host(192.168.110.11):hostport(8001)
-N: 远端不执行命令
-f: 将ssh放在后台执行
然后在笔记本浏览器中输入如下地址,访问控制台
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
参照内容: https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/creating-sample-user.md
编辑用于新增用户的文件add_user.yml
cat <<EOF > /tmp/add_user.yml apiVersion: v1 # 增加用户admin-user kind: ServiceAccount metadata: name: admin-user namespace: kubernetes-dashboard --- apiVersion: rbac.authorization.k8s.io/v1 # clusterrolebinding kind: ClusterRoleBinding metadata: name: admin-user roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: admin-user namespace: kubernetes-dashboard EOF
加载文件配置
[root@master config]# kubectl apply -f /tmp/add_user.yaml
用户创建成功,权限相关绑定也已经完成
执行命令,获取secret
[root@master config]# kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk ‘{print $1}‘)
输出内容大致如下
[root@master ~]# kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk ‘{print $1}‘) Name: admin-user-token-zckb9 Namespace: kubernetes-dashboard Labels: <none> Annotations: kubernetes.io/service-account.name: admin-user kubernetes.io/service-account.uid: 11071726-a225-11ea-959c-08002744270a Type: kubernetes.io/service-account-token Data ==== ca.crt: 1025 bytes namespace: 20 bytes token: eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXpja2I5Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIxMTA3MTcyNi1hMjI1LTExZWEtOTU5Yy0wODAwMjc0NDI3MGEiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZXJuZXRlcy1kYXNoYm9hcmQ6YWRtaW4tdXNlciJ9.gulUhc-oKe7M3AXzBp75vyowiVNtPPpZUJXymMhvk6jyk1CtMkMA-432knTULV0iACpEgGDYrN-IY7PBXVbxMLN6K_eajHQxbmFYx9p_m24Caaya7_dEaoXysy3Cl91NhlofGrGLbQfOBKqZhrNDPAB8XxucDLyAtCAq36K2kmuH_ewm1LTmaV5T2-zNXIWaJGkEQ38cRnATq4NgiMIdkKDxGSiE_9QFWqTzYXXx5_La8v1eRMz425K5p_4Lnue0eqKGf6DUYTYtFO8yYumjLd9E5XPo5PzohKiLKMrr6FfLmIYEgDzqKeFXijpHCDJ4SfGAZrbSNBpYS9jzh4hzog
复制token行内容就可以用于登录控制台了
标签:manager err 指定 使用 配置环境 bind 加入集群 克隆虚拟机 join
原文地址:https://www.cnblogs.com/liawne/p/12991964.html