文章目录
1、前期准备
1、关闭防火墙和selinux
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
vim /etc/selinux/config
2、关闭交换分区
- 如果有交换分区的话,关掉,不需要交换分区(占用磁盘)
3、修改主机名和免密登录
[root@localhost ~]
[root@localhost ~]
[root@master ~]
[root@localhost ~]
[root@localhost ~]
[root@node1 ~]
[root@master ~]
[root@master ~]
[root@master ~]
host.conf hostname hosts hosts.allow hosts.deny
[root@master ~]
The authenticity of host 'node1 (192.168.200.11)' can't be established.
ECDSA key fingerprint is SHA256:ZJD5+SX9K5TIrhruYNsYjv8xCrndEXt4yrdCt077ejw.
ECDSA key fingerprint is MD5:bc:c9:43:fd:b0:19:f8:5e:15:a0:14:f2:ac:17:13:ff.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node1,192.168.200.11' (ECDSA) to the list of known hosts.
root@node1's password:
hosts 100% 201 267.3KB/s 00:00
[root@master ~]
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:I8nt/Be5ue9Rq2/u/zYvYCSgAQEHR15sYvwpIcFkqwE root@master
The key's randomart image is:
+---[RSA 2048]----+
|Eo***+. |
|..o==.+ . |
|. .o.= + . |
| o ..+o . . |
|. .+ S o . .|
| + . = ..|
| o . =.. |
| . + o+.|
| ...=B*O|
+----[SHA256]-----+
[root@master ~]# ssh-copy-id root@node1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@node1's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@node1'"
and check to make sure that only the key(s) you wanted were added.
[root@master ~]
Last login: Sun Nov 17 13:33:50 2024 from 192.168.200.1
[root@node1 ~]
4、内核参数
[root@master yum.repos.d]
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
modprobe br_netfilter
[root@master yum.repos.d]
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
5、安装docker
- 有一个重要的点就是kubelet使用的是systemd驱动,docker使用的cgroupfs驱动,有冲突
yum -y install yum-utils
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce
[root@master /]
{
"registry-mirrors": ["https://registry.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
systemctl enable docker --now
6、安装k8s源
[root@master /]
> [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
2、安装
1、安装k8s软件包
[root@master ~]
[root@master ~]
I1117 14:17:57.019109 2908 version.go:255] remote version is much newer: v1.31.2; falling back to: stable-1.23
k8s.gcr.io/kube-apiserver:v1.23.17
k8s.gcr.io/kube-controller-manager:v1.23.17
k8s.gcr.io/kube-scheduler:v1.23.17
k8s.gcr.io/kube-proxy:v1.23.17
k8s.gcr.io/pause:3.6
k8s.gcr.io/etcd:3.5.1-0
k8s.gcr.io/coredns/coredns:v1.8.6
[root@master ~]
Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.
https://registry.aliyuncs.com/google_containers
2、初始化k8s
kubeadm init --apiserver-advertise-address=192.168.200.10 --kubernetes-version=v1.23.0 --service-cidr=10.96.0.0/16 --pod-network-cidr=10.244.0.0/16 --image-repository=registry.aliyuncs.com/google_containers
--apiserver-advertise-address
--kubernetes-version=v1.23.0
--service-cidr
--pod-network-cid
--image-repository
3、安装calico网络插件
wget https://docs.projectcalico.org/v3.21/manifests/calico.yaml
policy/v1beta1 改成policy/v1
‘
kubectl -f https://docs.projectcalico.org/v3.21/manifests/calico.yaml
4、检查
[root@master ~]
NAMESPACE NAME READY STATUS RESTARTS AGE
default busybox 1/1 Running 0 32m
kube-system calico-kube-controllers-7f76d48f74-5zfg9 1/1 Running 0 44m
kube-system calico-node-jnqkl 1/1 Running 0 44m
kube-system calico-node-mwhnh 1/1 Running 0 44m
kube-system coredns-6d8c4cb4d-kt7df 1/1 Running 0 52m
kube-system coredns-6d8c4cb4d-rsr6j 1/1 Running 0 52m
kube-system etcd-master 1/1 Running 1 (41m ago) 52m
kube-system kube-apiserver-master 1/1 Running 1 (41m ago) 52m
kube-system kube-controller-manager-master 1/1 Running 1 (41m ago) 52m
kube-system kube-proxy-7cwv7 1/1 Running 1 (41m ago) 51m
kube-system kube-proxy-j5fph 1/1 Running 1 (41m ago) 52m
kube-system kube-scheduler-master 1/1 Running 1 (41m ago) 52m
[root@master ~]
NAME STATUS ROLES AGE VERSION
master Ready control-plane,master 53m v1.23.0
node1 Ready <none> 51m v1.23.0