Centos 7.9 Kubeadm安装k8s1.20.11

一、环境

主机用途
192.168.76.140k8s-master1
192.168.76.141k8s-node1

二、设置yum源

由于系统已经关闭,可以用centos9尝试

cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
vi /etc/yum.repos.d/CentOS-Base.repo



# 使用阿里云的yum源
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7



sudo yum clean all
sudo yum makecache
yum install wget 

三、系统操作

1.升级内核

wget https://linux.cc.iitk.ac.in/mirror/centos/elrepo/kernel/el7/x86_64/RPMS/kernel-lt-5.4.278-1.el7.elrepo.x86_64.rpm
yum localinstall kernel-lt-5.4.278-1.el7.elrepo.x86_64.rpm

awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
grub2-set-default 0 #根据自己实际情况定

设置默认启动内核

2.关闭swap,设置网络等

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/enforcing/disabled/' /etc/selinux/config
iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
swapoff -a      ##交换分区必须要关闭
sed -ri 's/.*swap.*/#&/' /etc/fstab      ##永久关闭swap分区,&符号在sed命令中代表上次匹配的结果
for i in $(ls /usr/lib/modules/$(uname -r)/kernel/net/netfilter/ipvs|grep -o "^[^.]*");do echo $i; /sbin/modinfo -F filename $i >/dev/null 2>&1 && /sbin/modprobe $i;done   ##加载模块


cat >> /etc/sysctl.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
vm.swappiness = 0
EOF

sysctl --system

四、安装docker 和 k8s

sudo yum remove docker*
sudo yum install -y yum-utils
#配置docker的yum地址
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#安装指定版本
sudo yum install -y docker-ce-20.10.7 docker-ce-cli-20.10.7 containerd.io-1.4.6
#启动&开机启动docker
systemctl enable docker --now
# docker加速配置
sudo mkdir -p /etc/docker
cat >> /etc/docker/daemon.json << EOF
{
  "registry-mirrors" : [ "https:\/\/jockerhub.com" ]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker




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=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 install -y kubelet-1.20.11 kubeadm-1.20.11 kubectl-1.20.11
systemctl enable kubelet.service
kubeadm config images list
ip addr
cat /etc/hosts
echo "192.168.76.140 k8s-master1" >> /etc/hosts
echo "192.168.76.141 k8s-node1" >> /etc/hosts

五、复制机器

修改IP
修改hostname

hostnamectl set-hostname k8s-node1
reboot

七、master运行

kubeadm init \
--apiserver-advertise-address=192.168.76.140 #本机ip \ 
--control-plane-endpoint=k8s-master1 #控制平面主机 \
--image-repository registry.aliyuncs.com/google_containers #镜像地址 \
--kubernetes-version v1.20.11  #版本 \
--service-cidr=10.96.0.0/16 #集群内部虚拟网络 \
--pod-network-cidr=10.0.0.0/16 #pod网络,注意不要和自己的ip重了

执行里面的代码

 mkdir -p $HOME/.kube
 sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
 sudo chown $(id -u):$(id -g) $HOME/.kube/config
 export KUBECONFIG=/etc/kubernetes/admin.conf

八、node运行

kubeadm join k8s-master1:6443 --token 7olu40.s70rr3hwfp2ewubc \
    --discovery-token-ca-cert-hash sha256:3fbcf8208047b94499b34fce241ce4dffff075763e7c2dffde1765b3d3d0616c 

主节点运行
在这里插入图片描述

九、安装calico

在k8s github上可以找到对应版本的calico,其他东西都可以在里面找
在这里插入图片描述

wget https://calico-v3-15.netlify.app/archive/v3.15/manifests/calico.yaml
kubectl apply -f calico.yaml

最后

vi /etc/kubernetes/manifests/kube-controller-manager.yaml
vi /etc/kubernetes/manifests/kube-scheduler.yaml 
注释port = 0

到这里就搭建完成了,后面可以搭建dashboard

十、测试

vi nginx-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1  # 指定Pod副本数
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest  # 使用最新的Nginx镜像
        ports:
        - containerPort: 80  # Nginx监听的端口


vi nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
      nodePort: 30080
  type: NodePort  # 外部访问的类型,指定主机端口


kubectl apply -f nginx-deployment.yaml 
kubectl apply -f nginx-service.yaml

在这里插入图片描述
访问
在这里插入图片描述

安装Kubernetes 1.27.3在CentOS 7.9上的步骤如下: 1. 配置Kubernetes的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=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. 安装Kubernetes集群软件。在终端中执行以下命令: ``` yum install -y kubeadm-1.27.3 kubelet-1.27.3 kubectl-1.27.3 ``` 3. 配置Containerd。在终端中执行以下命令: ``` wget https://github.com/containerd/containerd/releases/download/v1.7.0/cri-containerd-cni-1.7.0-linux-amd64.tar.gz tar xf cri-containerd-cni-1.7.0-linux-amd64.tar.gz -C / mkdir /etc/containerd containerd config default > /etc/containerd/config.toml vim /etc/containerd/config.toml ``` 在打开的文件中,将`sandbox_image`的值从`"registry.k8s.io/pause:3.8"`修改为`"registry.k8s.io/pause:3.9"`。 4. 启动Containerd并设置开机自启动。在终端中执行以下命令: ``` systemctl enable --now containerd ``` 5. 验证Containerd的版本。在终端中执行以下命令: ``` containerd --version ``` 这样,你就成功在CentOS 7.9安装Kubernetes 1.27.3。请确保按照上述步骤逐一执行,并根据需要进行相应的配置修改。 #### 引用[.reference_title] - *1* *3* [kubernetes 1.27.3 集群部署方案](https://blog.csdn.net/weixin_45623111/article/details/131683965)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [centOS安装K8s](https://blog.csdn.net/frankgy01/article/details/127936391)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值