马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
实验体系:CentOS7.9
实验环境:单节点虚拟机
配置国内软件源
- [root@k8s-master1 ~]# mv /etc/yum.repos.d/* /data
- [root@k8s-master1 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
- [root@k8s-master1 ~]# yum makecache
复制代码 添加host
- [root@k8s-master1 ~]# vi /etc/hosts
- 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
- ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- 172.29.1.101 k8s-master1
复制代码 关闭防火墙、selinux
- [root@k8s-master1 ~]# systemctl stop firewalld && systemctl disable firewalld
- [root@k8s-master1 ~]# setenforce 0
- [root@k8s-master1 ~]# cat /etc/selinux/config
- # This file controls the state of SELinux on the system.
- # SELINUX= can take one of these three values:
- # enforcing - SELinux security policy is enforced.
- # permissive - SELinux prints warnings instead of enforcing.
- # disabled - No SELinux policy is loaded.
- SELINUX=disabled
- # SELINUXTYPE= can take one of three values:
- # targeted - Targeted processes are protected,
- # minimum - Modification of targeted policy. Only selected processes are protected.
- # mls - Multi Level Security protection.
- SELINUXTYPE=targeted
复制代码 关闭swap分区
- [root@k8s-master1 ~]# swapoff -a # 临时关闭
- [root@k8s-master1 ~]# vim /etc/fstab # 注释到swap那一行 永久关闭
- # /etc/fstab: static file system information.
- #
- # Use 'blkid' to print the universally unique identifier for a
- # device; this may be used with UUID= as a more robust way to name devices
- # that works even if disks are added and removed. See fstab(5).
- #
- # <file system> <mount point> <type> <options> <dump> <pass>
- # / was on /dev/sda3 during installation
- UUID=af1f3f13-f592-42af-a4c1-fa38c19e4fda / ext4 errors=remount-ro 0 1
- # /boot/efi was on /dev/sda2 during installation
- UUID=0FF3-84A3 /boot/efi vfat umask=0077 0 1
- # /swapfile none swap sw 0 0
复制代码 安装docker
- [root@k8s-master1 ~]# cat /etc/yum.repos.d/docker-ce.repo
- [docker-ce-stable]
- name=Docker CE Stable - $basearch
- baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/stable
- enabled=1
- gpgcheck=1
- gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
- [docker-ce-stable-debuginfo]
- name=Docker CE Stable - Debuginfo $basearch
- baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/stable
- enabled=0
- gpgcheck=1
- gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
- [docker-ce-stable-source]
- name=Docker CE Stable - Sources
- baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/stable
- enabled=0
- gpgcheck=1
- gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
- [docker-ce-test]
- name=Docker CE Test - $basearch
- baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/test
- enabled=0
- gpgcheck=1
- gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
- [docker-ce-test-debuginfo]
- name=Docker CE Test - Debuginfo $basearch
- baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/test
- enabled=0
- gpgcheck=1
- gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
- [docker-ce-test-source]
- name=Docker CE Test - Sources
- baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/test
- enabled=0
- gpgcheck=1
- gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
- [docker-ce-nightly]
- name=Docker CE Nightly - $basearch
- baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/nightly
- enabled=0
- gpgcheck=1
- gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
- [docker-ce-nightly-debuginfo]
- name=Docker CE Nightly - Debuginfo $basearch
- baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/nightly
- enabled=0
- gpgcheck=1
- gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
- [docker-ce-nightly-source]
- name=Docker CE Nightly - Sources
- baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/nightly
- enabled=0
- gpgcheck=1
- gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
- [root@k8s-master1 ~]# yum install -y docker
- [root@k8s-master1 ~]# systemctl start docker && systemctl enable docker
复制代码 配置镜像加快
- [root@k8s-master1 ~]# vi /etc/docker/daemon.json
- {
- # 配置为自己的阿里镜像加速地址
- "registry-mirrors": ["https://8740sp47.mirror.aliyuncs.com"]
- }
- [root@k8s-master1 ~]# systemctl daemon-reload
- [root@k8s-master1 ~]# systemctl restart docker
复制代码 安装containerd
- [root@k8s-master1 ~]# yum install -y containerd
- [root@k8s-master1 ~]# mkdir -p /etc/containerd
- [root@k8s-master1 ~]# containerd config default | sudo tee /etc/containerd/config.toml
- [root@k8s-master1 ~]# vi /etc/containerd/config.toml
- # 修改或者添加这个选项
- [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
- SystemdCgroup = true
- # 修改此处替换成阿里云的源
- sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.7"
- [root@k8s-master1 ~]# systemctl restart containerd
- [root@k8s-master1 ~]# systemctl enable containerd
复制代码 配置Kubernetes仓库 安装kubelet kubeadm kubectl 并锁定版本
- [root@k8s-master1 ~]# vi /etc/yum.repos.d/kubernetes.repo
- [kubernetes]
- name=Kubernetes
- baseurl=https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.30/rpm/
- enabled=1
- gpgcheck=1
- gpgkey=https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.30/rpm/repodata/repomd.xml.key
- [root@k8s-master1 ~]# yum install -y kubelet kubeadm kubectl
复制代码 配置主节点
- # 替换成当前节点的ip
- [root@k8s-master1 ~]# kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address 172.29.1.101 --image-repository registry.aliyuncs.com/google_containers
- [root@k8s-master1 ~]# sudo mkdir -p $HOME/.kube
- [root@k8s-master1 ~]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
- [root@k8s-master1 ~]# sudo chown $(id -u):$(id -g) $HOME/.kube/config
- [root@k8s-master1 ~]# export KUBECONFIG=/etc/kubernetes/admin.conf
复制代码 安装网络插件
- [root@k8s-master1 ~]# kubectl apply -f kube-flannel.yaml
复制代码 检察节点状态并参加集群
- [root@k8s-master1 ~]# kubectl get nodes
- NAME STATUS ROLES AGE VERSION
- k8s-master1 Ready control-plane 22m v1.30.0
- [root@k8s-master1 ~]# kubeadm token create --print-join-command # 生成加入集群的命令
复制代码 移除master节点上的污点
- [root@k8s-master1 ~]# kubectl taint nodes k8s-master1 node-role.kubernetes.io/control-plane:NoSchedule-
- node/k8s-master1 untainted
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |