img

Kubernetes安装与部署

旁观者 1年前 ⋅ 623 阅读

Kubeadm安装Kubernetes环境

一.安装前准备:

1.准备至少三台机器(互通),其中一台作为master(需要2以上核心cpu),其他机器作为集群的node。(检查时间是否同步) 举例:三台centos服务器,地址分别为192.168.192.1,192.168.192.2,192.168.192.3

2.关闭防火墙和swap,selinux

3.修改/etc/hosts,将主机名与ip对应。

4.将桥接的IPV4流量传递到iptables 的链

cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

二.开始安装k8s

1.安装docker

2.添加阿里云YUM软件源

cat > /etc/yum.repos.d/kubernetes.repo << EOF
[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

3.安装kubelet,kubeadm,kubectl

yum install -y kubelet kubeadm kubectl --nogpgcheck

4.初始化kubeadm(master执行)

kubeadm init \
--apiserver-advertise-address=192.168.192.2 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.22.1 \
--service-cidr=10.2.0.0/16 \
--pod-network-cidr=192.168.0.0/16

结果如图:

kubeadm_init_result.png

5.安装Pod网络插件(master执行,出现失败手动pull镜像)

kubectl apply -f kube-flannel.yml

kube-flannel.yml

6.配置admin.conf(把/etc/kubernetes/admin.conf复制到节点的/etc/kubernetes/目录下,并配置环境变量)

vi ~/.bash_profile

添加:

export KUBECONFIG=/etc/kubernetes/admin.conf

source ~/.bash_profile

7.node节点加入集群(node执行,kubeadm init的结果返回)

kubeadm join \
192.168.192.2:6443 --token m5y7r8.wevj0rrffanpoig9 \
--discovery-token-ca-cert-hash sha256:c08dcc8a8804bad11d47bcba2d1d3a7213c10ebc422694c97d62437f48ed548e

8.检查node

kubectl get nodes

结果如图:

get_node.png

三.k8s卸载

kubeadm reset -f

modprobe -r ipip

lsmod

rm -rf ~/.kube/

rm -rf /etc/kubernetes/

rm -rf /etc/systemd/system/kubelet.service.d

rm -rf /etc/systemd/system/kubelet.service

rm -rf /usr/bin/kube*

rm -rf /etc/cni

rm -rf /opt/cni

rm -rf /var/lib/etcd

rm -rf /var/etcd

yum clean all

yum remove kube*


全部评论: 0

    我有话说: