k8s安装(v1.23.6)

安装初始环境

系统版本7.9 cpu 2c

主机节点节点ip
master192.168.20.122
node1192.168.20.123
node2192.168.20.124

1.修改主机名 方便后续区分(3台机器都添加信息 并独自修改自己的名字)

master

[root@localhost ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.20.122 master
192.168.20.123 node1
192.168.20.124 node2
[root@localhost ~]# hostname master
[root@localhost ~]# bash
[root@master ~]# 

node1

[root@localhost ~]# vim /etc/hosts
[root@localhost ~]# hostname node1
[root@localhost ~]# bash
[root@node1 ~]# 

node2

[root@localhost ~]# vim /etc/hosts
[root@localhost ~]# hostname node2
[root@localhost ~]# bash
[root@node2 ~]# 

2.免密登录

master操作

ssh-keygen

进行三次回车

ssh-copy-id -i root@node2
ssh-copy-id -i root@node3

3.关闭防火墙

3台全部操作

systemctl stop firewalld && systemctl disable firewalld

4.配置slinux并关闭swap分区

3台全部操作

[root@node2 ~]# setenforce 0
[root@node2 ~]# sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@node2 ~]# getenforce 
Permissive
[root@master ~]# swapoff -a
[root@master ~]# sed -i '/swap/ s/^\(.*\)$/#\1/g' /etc/fstab
[root@node2 ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Tue Sep 17 08:58:48 2024
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=5c0b82f2-5f15-4e41-ab54-2da67e588397 /boot                   xfs     defaults        0 0
#/dev/mapper/centos-swap swap                    swap    defaults        0 0

5.安装一些软件

3台全部操作

yum install -y device-mapper-persistent-data lvm2 wget net-tools nfs-utils lrzsz gcc gcc-c++ make cmake libxm12-devel openssl-devel curl curl-devel unzip sudo ntp libaio-devel wget vim ncurses-devel autoconf automake zlib-devel python-devel epel-release openssh-server socat ipvsadm conntrack ntpdate telnet ipvsadm npdate

6.打开转发–导入模块

3台全部操作

[root@master ~]# modprobe ip_vs_rr
[root@master ~]# modprobe br_netfilter     
[root@master ~]# lsmod | grep br_netfilter
br_netfilter           28672  0
[root@master ~]# vim /etc/modules-load.d/k8s.conf
[root@master ~]# cat >> /etc/modules-load.d/k8s.conf << EOF
> br_netfilter
> EOF
[root@master ~]# scp /etc/modules-load.d/k8s.conf root@node1:/etc/modules-load.d/
k8s.conf                                                                                      100%   13     3.1KB/s   00:00    
[root@master ~]# scp /etc/modules-load.d/k8s.conf root@node2:/etc/modules-load.d/
k8s.conf                                

7.修改内核参数

[root@master ~]# cat <<EOF >> /etc/sysctl.conf
> net.bridge.bridge-nf-call-ip6tables = 1
> net.bridge.bridge-nf-call-iptables = 1
> net.ipv4.ip_nonlocal_bind = 1
> net.ipv4.ip_forward = 1
> vm.swappiness=0
> EOF
[root@master ~]# sysctl -p

全部执行 sysctl -p

[root@master ~]# scp /etc/sysctl.conf root@node1:/etc/
sysctl.conf                                                                                   100%  598   165.0KB/s   00:00    
[root@master ~]# scp /etc/sysctl.conf root@node2:/etc/
sysctl.conf                                             

安装docker

1.使用阿里云的源

指定docker版本安装

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install -y docker-ce-20.10.0 docker-ce-cli-20.10.0 containerd.io

配置加速地址使用docker

[root@master ~]#  vim /etc/docker/daemon.json 
[root@master ~]# cat /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://hub.atomgit.com"]
}
[root@master ~]# systemctl daemon-reload 
[root@master ~]# systemctl start docker

传输文件 node节点重新加载 重启

[root@master ~]# scp /etc/docker/daemon.json root@node1:/etc/docker/
daemon.json                                                                                   100%   54    13.2KB/s   00:00    
[root@master ~]# scp /etc/docker/daemon.json root@node2:/etc/docker/
daemon.json                             

安装k8s

3台全部安装
使用阿里云的源

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

安装指定版本的

yum install -y kubelet-1.23.6 kubeadm-1.23.6 kubectl-1.23.6

安装CoreDNS提供DNS解析服务

docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.

改个名字

docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.4 registry.aliyuncs.com/google_containers/coredns:v1.8.4

安装tab键位

source <(kubeadm completion bash)
source <(kubectl completion bash)
vi .bashrc
末尾行添加
source <(kubeadm completion bash)
source <(kubectl completion bash)

初始化(master)

systemctl enable docker && systemctl enable kubelet
kubeadm init \
--apiserver-advertise-address=192.168.20.122 \
--image-repository registry.aliyuncs.com/google_containers \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16 \
--kubernetes-version v1.23.6 \
--image-repository registry.aliyuncs.com/google_containers

初始化成功

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

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

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.20.122:6443 --token 2p11ki.9joe3ada46h650jr \
	--discovery-token-ca-cert-hash sha256:a514595d8b1af2d411a36f087343813ab88635d76cbac3eec6fcdd7b3bcf6f43 

初始化完成后 配置命令环境

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节点操作
加入集群信息 master初始化成功最后一行复制

kubeadm join 192.168.20.122:6443 --token 2p11ki.9joe3ada46h650jr \
> --discovery-token-ca-cert-hash sha256:a514595d8b1af2d411a36f087343813ab88635d76cbac3eec6fcdd7b3bcf6f43 

加入成功后显示

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

master
查看集群状态

[root@master ~]# kubectl get node
NAME     STATUS     ROLES                  AGE     VERSION
master   NotReady   control-plane,master   11m     v1.23.6
node1    NotReady   <none>                 4m49s   v1.23.6
node2    NotReady   <none>                 4m42s   v1.23.6

重要部分 网络插件的安装

calico安装
下载calico文件

curl -O https://docs.tigera.io/archive/v3.25/manifests/calico.yaml

修改一下文件

vim calico.yaml 
找到以下内容 取消注释 修改ip
- name: CALICO_IPV4POOL_CIDR
  value: "10.244.0.0/16"

注释文件中的外网地址拉取

sed -i 's#docker.io/##g' calico.yaml
[root@master ~]# grep image calico.yaml
          image: docker.io/calico/cni:v3.25.0
          imagePullPolicy: IfNotPresent
          image: docker.io/calico/cni:v3.25.0
          imagePullPolicy: IfNotPresent
          image: docker.io/calico/node:v3.25.0
          imagePullPolicy: IfNotPresent
          image: docker.io/calico/node:v3.25.0
          imagePullPolicy: IfNotPresent
          image: docker.io/calico/kube-controllers:v3.25.0
          imagePullPolicy: IfNotPresent

拉取calico镜像,所有节点都要执行\

文件pull不下来

从csdn站内搜索calico-image-v3.25.0.zip进行下载
解压后下载好通过docker进行导入

docker load -i calico-image-v3.25.0.tar
docker pull calico/cni:v3.25.0
docker pull calico/node:v3.25.0
docker pull calico/kube-controllers:v3.25.0

开始部署

kubectl apply -f calico.yaml
[root@master ~]# kubectl get nodes 
NAME     STATUS   ROLES                  AGE     VERSION
master   Ready    control-plane,master   3h42m   v1.23.6
node1    Ready    <none>                 3h41m   v1.23.6
node2    Ready    <none>                 3h41m   v1.23.6

[root@master ~]# kubectl get pods -n kube-system
NAME                                       READY   STATUS    RESTARTS        AGE
calico-kube-controllers-64cc74d646-htbdb   1/1     Running   0               4m33s
calico-node-9v729                          1/1     Running   0               4m33s
calico-node-jwjxk                          1/1     Running   0               4m33s
calico-node-t6hhq                          1/1     Running   0               4m33s
coredns-6d8c4cb4d-5kxp4                    1/1     Running   0               3h43m
coredns-6d8c4cb4d-t2485                    1/1     Running   0               3h43m
etcd-master                                1/1     Running   7 (125m ago)    3h43m
kube-apiserver-master                      1/1     Running   2 (125m ago)    3h43m
kube-controller-manager-master             1/1     Running   2 (125m ago)    3h43m
kube-proxy-jdq7z                           1/1     Running   0               3h42m
kube-proxy-mzmfs                           1/1     Running   0               3h42m
kube-proxy-wxkzh                           1/1     Running   1 (125m ago)    3h43m
kube-scheduler-master                      1/1     Running   12 (125m ago)   3h43m

k8s集群安装完成

参考文献 基于calico部署k8s集群k8s-1.23.6
原文链接:https://blog.csdn.net/shyboyandgirl/article/details/141460594
K8s安装部署–超级详细(无坑,v1.23)
原文链接:https://blog.csdn.net/m0_51720581/article/details/131153894

KubernetesK8s)是一个用于自动化容器部署、扩展和管理的开源平台。在K8s的不同版本中,v1.23.6是较新的版本。下面是关于如何进行K8s v1.23.6的二进制部署的简要步骤。 1. 准备服务器:首先需要准备一台或多台服务器,最好是基于Linux操作系统的服务器。确保服务器可通过SSH远程访问,并且具有足够的计算和存储资源来运行Kubernetes集群。 2. 安装Docker:Kubernetes使用Docker作为容器运行时环境。在服务器上安装Docker,并确保其正确配置和运行。 3. 下载Kubernetes二进制文件:在官方Kubernetes GitHub页面上,找到v1.23.6的版本发布并下载相关的二进制文件。 4. 配置Master节点:选择其中一台服务器作为Master节点,并在此节点上进行Kubernetes的初始化配置。通过执行"kubeadm init"命令,可以完成对Master节点的初始化。 5. 配置Worker节点:选择剩余的服务器作为Worker节点,并通过执行"kubeadm join"命令,将这些节点加入到Kubernetes集群中。 6. 安装网络插件:Kubernetes集群需要一个网络插件来实现容器间的网络通信。根据自己的需求,选择并安装合适的网络插件,如Calico、Flannel等。 7. 部署Dashboard(可选):Dashboard提供了一个Web界面来管理和监控Kubernetes集群。根据需求,可以选择安装并配置Dashboard。 通过以上步骤,可以成功完成Kubernetes v1.23.6的二进制部署。注意,这只是一个简要的步骤概述,具体的部署过程可能会因环境和需求而有所不同。在进行部署之前,建议仔细阅读文档和相关教程,以确保正确理解和执行每个步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值