用kubeadm1.27.4来搭两台简单的kubernets,可以做研发的测试环境
1、装好两台rocky9操作系统
2、配置好主机名和selinux,关闭iptables
3、yum install -y conntrack ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git
4、systemctl stop firewalld && systemctl disable firewalld
5、yum -y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables -F && service iptables save
6、swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab 关闭swap分区
关闭selinux 为disabled
7、
/etc/sysctl.d/kubernetes.conf
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
modprobe br_netfilter
7、改时区 timedatectl set-timezone Asia/Shanghai
timedatectl set-local-rtc 0
8、/etc/systemd
改 journald.conf
Storage=persistent
Compress=yes
SyncIntervalSec=5m
RateLimitInterval=30s
RateLimitBurst=100
SystemMaxUse=10G
SystemMaxFileSize=200M
MaxRetentionSec=2week
ForwardToSyslog=no
systemctl restart systemd-journald
9、/etc/sysconfig/modules/ipvs.modules
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4
10 yum install -y yum-utils device-mapper-persistent-data lvm2
安装docker {BANNED}{BANNED}{BANNED}最佳佳佳新版
/etc/docker/daemon.json
{
"registry-mirrors": ["",""],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
systemctl daemon-reload && systemctl enable docker && systemctl start docker
11 安装kubernetes
/etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=
yum install -y kubelet kubeadm kubectl
11 /etc/systemd/system
ln -s kubelet.service.d -> /usr/lib/systemd/system/kubelet.service.d
kubelet.service.d里面文件内容
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
EnvironmentFile=-/etc/sysconfig/kubelet
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS
12 yum install kubernetes-cni -y
13 containerd config default > /etc/containerd/config.toml
修改 sandbox_image = "registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.9"
14 修改/etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.9"
15 更改镜像为国内
ctr images pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.9
ctr images pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.27.4
ctr images pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.27.4
ctr images pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.27.4
ctr images pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.27.4
ctr images pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.7-0
ctr images pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:v1.10.1
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.9
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.9 registry.k8s.io/pause:3.6
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6 registry.k8s.io/pause:3.6
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.27.4
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.27.4 k8s.gcr.io/kube-apiserver:v1.27.4
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.27.4
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.27.4 registry.k8s.io/kube-controller-manager:v1.27.4
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.27.4
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.27.4 registry.k8s.io/kube-scheduler:v1.27.4
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.27.4
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.27.4 registry.k8s.io/kube-proxy:v1.27.4
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.7-0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.7-0 registry.k8s.io/etcd:3.5.7-0
docker pull docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.27.4
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.27.4 registry.k8s.io/kube-proxy:v1.27.4
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:v1.10.1
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:v1.10.1 registry.k8s.io/coredns/coredns:v1.10.1
16 建立/etc/crictl.yaml
runtime-endpoint: unix:///var/run/containerd/containerd.sock
image-endpoint: unix:///var/run/containerd/containerd.sock
timeout: 0
debug: false
pull-image-on-create: false
kubeadm init --kubernetes-version 1.27.4 --apiserver-advertise-address=(你的服务器网卡ip) --service-cidr=10.96.0.0/16 --pod-network-cidr=10.244.0.0/16 --image-repository registry.cn-hangzhou.aliyuncs.com/google_containers --control-plane-endpoint=(你的服务器网卡ip)
直到出现这个为止
Your Kubernetes control-plane has initialized successfully!
阅读(257) | 评论(0) | 转发(0) |