标签:http disco sch 系统 ready export service ocs tca
硬件要求来自 <https://docs.projectcalico.org/getting-started/kubernetes/quickstart>
主机名 | IP | 角色 | 操作系统 | CPU/MEM |
---|---|---|---|---|
master | 192.168.118.20 | Master | CentOS7 | 2core/2GB |
node1 | 192.168.118.21 | node1 | CentOS7 | 2core/2GB |
node2 | 192.168.118.22 | node2 | CentOS7 | 2core/2GB |
?systemctl stop firewalld; systemctl disable firewalld?
?setenforce 0;?sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config?
?swapoff -a; sed -i "s/\/dev\/mapper\/centos-swap/\#\/dev\/mapper\/centos-swap/g" /etc/fstab?
如果不想关闭swap,可以跳过检查
vim /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
在初始化时加入参数--ignore-preflight-errors=Swap
?wget -O /etc/yum.repos.d/CentOS7-Aliyun.repo http://mirrors.aliyun.com/repo/Centos-7.repo??
[root@master ~]# cat <<EOF >? /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
使配置生效
[root@master ~]# sysctl --system
vim /etc/hosts
192.168.118.20 master
192.168.118.21 node1
192.168.118.22 node2
?wget -O /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo?
?yum install docker-ce -y?
?systemctl enable docker;systemctl start docker?
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-‘EOF‘
{
"registry-mirrors": ["https://dkqah25p.mirror.aliyuncs.com"], // 换成自己的阿里云镜像加速器地址
"exec-opts": ["native.cgroupdriver=systemd"] // 默认cgroupfs,k8s官方推荐systemd,否则初始化出现Warning
}
EOF
systemctl daemon-reload
systemctl restart docker
[root@master ~]# docker info |grep Cgroup
Cgroup Driver: systemd
?
cat <<EOF > /etc/yum.repos.d/kubernetes.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
yum install -y kubelet kubeadm kubectl?
systemctl enable kubelet;systemctl start kubelet?
#此时启动不成功正常,初始化后有配置文件了就启动了
?
kubeadm init --kubernetes-version=1.18.5 --apiserver-advertise-address=192.168.118.20 --image-repository mirrorgcrio --service-cidr=10.10.0.0/16 --pod-network-cidr=10.122.0.0/16 --ignore-preflight-errors=Swap,NumCPU
--kubernetes-version:k8s版本
--apiserver-advertise-address:spiserver的地址
--image-repository:由于kubeadm 默认从官网k8s.grc.io下载所需镜像,国内无法访问,因此需要通过–image-repository指定mirrorgcrio。
--ignore-preflight-errors=Swap,NumCPU:跳过swap和cpu检查
出现以下内容是初始化成功
Your Kubernetes control-plane 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/
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 192.168.118.20:6443 --token akiiod.ajlbeux62nhin6kw --discovery-token-ca-cert-hash sha256:76a5cfca9c7c90e319a0c27731dfab0d6c40932ba4c10b0dfb46d9528492a1d9
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
如果是root 可以直接执行
export KUBECONFIG=/etc/kubernetes/admin.conf
以上两个二选一即可,我这里用root
export KUBECONFIG=/etc/kubernetes/admin.conf
确认master各组件状态
[root@k8s-master docker]# kubectl get cs
NAME STATUS MESSAGE ERROR
scheduler Healthy ok
controller-manager Healthy ok
etcd-0 Healthy {"health":"true"}
将admin配置文件复制到所有node节点
scp /etc/kubernetes/admin.conf node1:/etc/kubernetes/
scp /etc/kubernetes/admin.conf node2:/etc/kubernetes/
配置环境变量
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
立即生效
source ~/.bash_profile
当初始化中途出现报错时,先重置集群,后重新初始化集群
kubeadm reset
systemctl daemon-reload
systemctl restart kubelet
iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
iptables -nL #检查防火墙规则是否清空
netstat -antlp #检查端口是否全被放开
?
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
[root@master ~]# kubectl get pod -n kube-system -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
calico-kube-controllers-58b656d69f-jk7fr 1/1 Running 0 3m42s 10.122.219.67 master <none> <none>
calico-node-2jhdt 1/1 Running 0 3m42s 192.168.118.20 master <none> <none>
coredns-54f99b968c-5wmbp 1/1 Running 0 11m 10.122.219.66 master <none> <none>
coredns-54f99b968c-lgvsw 1/1 Running 0 11m 10.122.219.65 master <none> <none>
etcd-master 1/1 Running 0 11m 192.168.118.20 master <none> <none>
kube-apiserver-master 1/1 Running 0 11m 192.168.118.20 master <none> <none>
kube-controller-manager-master 1/1 Running 0 11m 192.168.118.20 master <none> <none>
kube-proxy-7ms45 1/1 Running 0 11m 192.168.118.20 master <none> <none>
kube-scheduler-master 1/1 Running 0 11m 192.168.118.20 master <none> <none>
kubeadm join 192.168.118.20:6443 --token akiiod.ajlbeux62nhin6kw --discovery-token-ca-cert-hash sha256:76a5cfca9c7c90e319a0c27731dfab0d6c40932ba4c10b0dfb46d9528492a1d9 --ignore-preflight-errors=Swap,NumCPU
[root@master ~]# kubectl get pod -n kube-system -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
calico-kube-controllers-58b656d69f-jk7fr 1/1 Running 0 7m39s 10.122.219.67 master <none> <none>
calico-node-2jhdt 1/1 Running 0 7m39s 192.168.118.20 master <none> <none>
calico-node-4258m 0/1 Running 0 119s 192.168.118.21 node1 <none> <none>
calico-node-lpcvq 0/1 Running 0 113s 192.168.118.22 node2 <none> <none>
coredns-54f99b968c-5wmbp 1/1 Running 0 15m 10.122.219.66 master <none> <none>
coredns-54f99b968c-lgvsw 1/1 Running 0 15m 10.122.219.65 master <none> <none>
etcd-master 1/1 Running 0 15m 192.168.118.20 master <none> <none>
kube-apiserver-master 1/1 Running 0 15m 192.168.118.20 master <none> <none>
kube-controller-manager-master 1/1 Running 0 15m 192.168.118.20 master <none> <none>
kube-proxy-65tr6 1/1 Running 0 119s 192.168.118.21 node1 <none> <none>
kube-proxy-7ms45 1/1 Running 0 15m 192.168.118.20 master <none> <none>
kube-proxy-h7sg5 1/1 Running 0 113s 192.168.118.22 node2 <none> <none>
kube-scheduler-master 1/1 Running 0 15m 192.168.118.20 master <none> <none>
[root@master ~]# kubectl get node -n kube-system -owide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIM
Emaster Ready master 15m v1.18.5 192.168.118.20 <none> CentOS Linux 7 (Core) 3.10.0-693.el7.x86_64 docker://19.3.12
node1 Ready <none> 2m3s v1.18.5 192.168.118.21 <none> CentOS Linux 7 (Core) 3.10.0-693.el7.x86_64 docker://19.3.12
node2 Ready <none> 117s v1.18.5 192.168.118.22 <none> CentOS Linux 7 (Core) 3.10.0-693.el7.x86_64 docker://19.3.12
到此,简单的k8s集群就安装完毕了
参考文章:https://www.jianshu.com/p/ad27168bebb5
标签:http disco sch 系统 ready export service ocs tca
原文地址:https://blog.51cto.com/jiayimeng/2507664