k8s集群部署
k8s集群部署准备dockerk8s安装部署三台centos7:192.168.11.180、181、183准备// 1.分别设置-----------------------------------------------------hostnamectl set-hostname k8s-masterhostnamectl set-hostname k8s-node01hostnamectl
·
三台centos7:
192.168.11.180、181、183
准备
// 1.分别设置-----------------------------------------------------
hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node01
hostnamectl set-hostname k8s-node02
// 2.每台加--------------------------------------------------------
vim /etc/hosts
192.168.11.180 k8s-master
192.168.11.181 k8s-node01
192.168.11.183 k8s-node02
// 3.时间节点确保同步------------------------------------------
yum -y install ntp ntpdate
// 设置系统时间与⽹络时间同步
ntpdate cn.pool.ntp.org
// 将系统时间写⼊硬件时间
hwclock --systohc
// 强制系统时间写⼊CMOS中防⽌重启失效
hwclock -w
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
// 验证时间是否正确
date
// 4.依赖------------------------------------------------------------
yum install -y conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git iproute lrzsz bash-completion tree bridge-utils unzip bind-utils gcc
// 5.防火墙、selinux等设置-----------------------------------
systemctl stop firewalld && systemctl disable firewalld
// 安装并置空iptables
yum -y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables -F && service iptables save
// 关闭selinux
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
// 关闭不需要的服务
systemctl stop postfix && systemctl disable postfix
// 关闭交互分区
swapoff -a && sed -i 's/.*swap.*/#&/' /etc/fstab
// 6.系统参数优化------------------------------------------------
modprobe br_netfilter
cat > kubernetes.conf <<EOF
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
vm.swappiness=0
vm.overcommit_memory=1
vm.panic_on_oom=0
fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=1048576
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_conntrack_max=2310720
EOF
cp kubernetes.conf /etc/sysctl.d/kubernetes.conf
rm -rf kubernetes.conf
sysctl -p /etc/sysctl.d/kubernetes.conf
// 系统文件数调整
echo "* soft nofile 65536" >> /etc/security/limits.conf
echo "* hard nofile 65536" >> /etc/security/limits.conf
docker
// 安装依赖环境
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
// 软件源信息
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
// docker-ce稳定版本
yum install -y docker-ce-18.09.9-3.el7
// 设置docker daemon.json⽂件、源地址、存储⽬录、⽇志规则、存储⽅式
mkdir /etc/docker
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://u9nigs6v.mirror.aliyuncs.com",
"http://hubmirror.c.163.com","https://docker.mirrors.ustc.edu.cn"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
]
}
EOF
// 启动docker服务并设置docker为开机⾃启动
sudo systemctl enable docker
sudo systemctl daemon-reload
sudo systemctl start docker
或者
sudo systemctl restart docker
// 查看启动状态
systemctl status docker
k8s
安装
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
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum -y install kubelet-1.18.6 kubeadm-1.18.6 kubectl-1.18.6
// kubelet启动失败也不要紧
systemctl enable kubelet && systemctl start kubelet
部署
1.主节点
// 若是执行失败,可以尝试kubeadm reset/kubeadm init等等
kubeadm init --kubernetes-version=v1.18.6 --image-repository registry.cn-hangzhou.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap
// 会输出下面----------------记录下
// kubeadm join 192.168.11.180:6443 --token uw2pnz.tr0yxkjsyzw133o7 \
--discovery-token-ca-cert-hash sha256:5376e8b927bb6d3623d43ee60b0adc3dff0a42b1d4516fa4172c4b09468e0b19
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
2.从节点
kubeadm join 192.168.11.180:6443 --token uw2pnz.tr0yxkjsyzw133o7 \
--discovery-token-ca-cert-hash sha256:5376e8b927bb6d3623d43ee60b0adc3dff0a42b1d4516fa4172c4b09468e0b19
3.主节点
// 可以看到集群已经有了,但处于NotReady状态
[root@k8s-master ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master NotReady master 24m v1.18.6
k8s-node01 NotReady <none> 20m v1.18.6
k8s-node02 NotReady <none> 20m v1.18.6
// 是因为网站被墙了,建议在文件添加一条
vim /etc/hosts
199.232.68.133 raw.githubusercontent.com
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yml
// 查看flannel的状态,确保都是Running状态
kubectl get pod -n kube-system
// 发现都是Ready状态
kubectl get nodes -o wide
卸载
sudo kubeadm reset -f
sudo rm -rvf $HOME/.kube
// 没有~/.kube
sudo rm -rvf ~/.kube/
sudo rm -rvf /etc/kubernetes/
sudo rm -rvf /etc/systemd/system/kubelet.service.d
sudo rm -rvf /etc/systemd/system/kubelet.service
// kubeadm、kubectl、kubelet
sudo rm -rvf /usr/bin/kube*
sudo rm -rvf /etc/cni
sudo rm -rvf /opt/cni
sudo rm -rvf /var/lib/etcd
sudo rm -rvf /var/etcd
sudo apt-get remove kube*
sudo -y yum remove kubelet-1.18.6 kubeadm-1.18.6 kubectl-1.18.6
// 卸载docker
systemctl stop docker
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine \
docker-engine
df -h
sudo rm -rvf /var/lib/docker
查看启动日志 journalctl -f或者 journalctl -xe
更多推荐
已为社区贡献1条内容
所有评论(0)