使用kubeadm在Centos7系统上部署kubernetes
采用2台虚拟机进行搭建,一台master,一台node
IP | 主机名 |
---|---|
10.133.92.34 | master |
10.133.92.35 | nodeone |
hostnamectl set-hostname 主机名
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
sed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/sysconfig/selinux
sed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/selinux/config
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
然后执行 sysctl -p
使用aliyun源进行安装
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
rpm --import https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
yum -y install docker-ce
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=0
EOF
yum -y install epel-release
yum clean all
yum makecache
yum -y install kubectl-1.18.2 kubelet-1.18.2 kubeadm-1.18.2
systemctl enable docker && systemctl start docker
systemctl enable kubelet && systemctl start kubelet
所需镜像列表
#!/bin/bash
images=(k8s.gcr.io/kube-apiserver:v1.18.2 k8s.gcr.io/kube-controller-manager:v1.18.2 k8s.gcr.io/kube-scheduler:v1.18.2
k8s.gcr.io/kube-proxy:v1.18.2 k8s.gcr.io/pause:3.2 k8s.gcr.io/etcd:3.4.3-0 k8s.gcr.io/coredns:1.6.7)
for imageName in ${images[@]} ; do
docker pull carefree666/$imageName
docker tag carefree666/$imageName k8s.gcr.io/$imageName
docker rmi carefree666/$imageName
done
- - -上方部署集群所有节点机器都需要执行,下方只在master节点机器执行- - -
执行下方命令(只在master机器执行,10.133.92.34为master机器IP)
kubeadm init --kubernetes-version=v1.18.2 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.133.92.34
执行完成后,记录生成的最后部分内容(kubeadm join ***),此内容需要在其它节点加入Kubernetes集群时执行
在/etc/profile末尾增加
export KUBECONFIG=/etc/kubernetes/admin.conf
添加完成后执行 source /etc/profile
注:也可以选择其它网络插件,如flannel
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
所需镜像列表
docker pull carefree666/calico/node:v3.13.3
docker tag carefree666/calico/node:v3.13.3 calico/node:v3.13.3
环境安装完成,其它节点可执行master初始化最终的命令加入集群
kubectl get cs -查看kubernetes集群状态
kubectl get nodes -查看节点状态
kubectl get pods --all-namespaces -查看pods状态
kubeadm reset -重置kubernetes
journalctl -xefu kubelet -kubernetes日志
其它命令可查找相关文档
安装kubernetes-dashboard-2.0.0与metrics-server-0.3.6
以上内容为本人通过各个网站安装文档进行亲身实践后整理,如有问题,请留言