云原生-kubernetes集群部署

基于kubeadm部署kubernetes集群


一:环境准备

三台服务器,一台master,两台node,master节点必须是2核cpu

节点名称IP地址
master10.0.0.220
node-110.0.0.221
node-210.0.0.222
node-310.0.0.223
1.所有服务器关闭防火墙和selinux(这个条件一定要注意千万准备好)
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# sed -i '/^SELINUX=/c SELINUX=disabled/' /etc/selinux/config
[root@localhost ~]# swapoff -a  临时关闭
[root@localhost ~]# sed -i 's/.*swap.*/#&/' /etc/fstab 永久关闭
注意:
	关闭所有服务器的交换分区
	所有节点操作
    上面是临时关闭交换分区不一定有用,一定要进入到/etc/fstab 中删除那一行
2.保证yum仓库可用
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache fast
注意:
	使用国内yum源
	所有节点操作
3.修改主机名
[root@localhost ~]# hostnamectl set-hostname master
[root@localhost ~]# hostnamectl set-hostname node-1
[root@localhost ~]# hostnamectl set-hostname node-2
[root@localhost ~]# hostnamectl set-hostname node-3
注意:
	所有节点操作
4.添加本地解析
[root@master ~]# cat >> /etc/hosts <<eof
10.0.0.220 master
10.0.0.221 node-1
10.0.0.222 node-2
10.0.0.223 node-3
eof
注意:
	所有节点操作
5.安装容器(这步骤可以写个脚本)

[root@master ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@master ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@master ~]# yum -y install docker-ce
[root@master ~]# systemctl start docker
[root@master ~]# systemctl enable docker
[root@master ~]# vim /etc/docker/daemon.json(这步骤可做可不做,如果有这方面的报错的话就做一下)

{
  "exec-opts": ["native.cgroupdriver=systemd"]
}
[root@master ~]# systemctl restart docker

[kubelet-check] The HTTP call equal to ‘curl -sSL http://localhost:10248/healthz’ failed with error: Get “http://localhost:10248/healthz”: dial tcp [::1]:10248: connect: connection refused.
[kubelet-check] It seems like the kubelet isn’t running or healthy.
注意:
	所有节点操作
6.安装kubeadm和kubelet(这个也写成脚本每台机器都要做)

[root@master ~]# 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
[root@master ~]# yum -y install kubeadm  kubelet  kubectl ipvsadm(这个可以指定版本上面我用的是1.23.5的版本)
注意:
	所有节点操作
	这里安装的是最新版本(也可以指定版本号:kubeadm-1.19.4)
7.配置kubelet的cgroups
[root@master ~]# cat >/etc/sysconfig/kubelet<<EOF
KUBELET_EXTRA_ARGS="--cgroup-driver=cgroupfs --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.1"
EOF
k8s.gcr.io/pause:3.6
8.加载内核模块(这个也写成脚本,每台机器都要做)

[root@master ~]# modprobe br_netfilter
注意:
	所有节点操作
9.修改内核参数
[root@master ~]# cat >> /etc/sysctl.conf <<eof
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
vm.swappiness=0
eof
[root@master ~]# sysctl -p
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
vm.swappiness = 0
注意:
	所有节点操作

二:部署Kubernetes

1.镜像下载(在他资源库获取这些镜像)

https://www.xingdiancloud.cn/index.php/s/6GyinxZwSRemHPz
注意:
	下载后上传到所有节点
2.镜像导入(这个等上面那个镜像获取完再bash这个镜像导入的脚本,这个每台服务器都要做)
[root@master ~]# cat image_load.sh
#!/bin/bash
image_path=`pwd`
for i in `ls "${image_path}" | grep tar`
do
        docker load  < $i
done
[root@master ~]# bash image_load.sh
注意:
	所有节点操作
3.master节点初始化(这个只需要主节点做)

[root@master ~]# kubeadm init --kubernetes-version=1.23.1 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.0.0.220

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 10.0.0.220:6443 --token mzrm3c.u9mpt80rddmjvd3g \(这步node节点做复制就行,但必须是主节点获取的这个信息不要直接复制我的这个)
        --discovery-token-ca-cert-hash sha256:fec53dfeacc5187d3f0e3998d65bd3e303fa64acd5156192240728567659bf4a

4.安装pod插件

文件(kube-flannel.yml)在我的下载库里面获取就行

报created就行了

 (下面这步跟上面是一个意思)

[root@master ~]# wget http://www.xingdiancloud.cn:92/index.php/s/3Ad7aTxqPPja24M/download/flannel.yaml
[root@master ~]# kubectl create -f flannel.yaml
5.将node加入工作节点(在node节点上操作)
[root@node-1 ~]# kubeadm join 10.0.0.220:6443 --token mzrm3c.u9mpt80rddmjvd3g --discovery-token-ca-cert-hash sha256:fec53dfeacc5187d3f0e3998d65bd3e303fa64acd5156192240728567659bf4a
注意:
这里使用的是master初始化产生的token
这里的token时间长了会改变,需要使用命令获取,见下期内容
没有记录集群 join 命令的可以通过以下方式重新获取:
kubeadm token create --print-join-command --ttl=0
6.master节点查看集群状态(在主节点查看状态是不是ready,如果是说明就可以了)
[root@master ~]# kubectl get nodes
NAME     STATUS   ROLES                  AGE     VERSION
master   Ready    control-plane,master   26m     v1.23.1
node-1   Ready    <none>                 4m45s   v1.23.1
node-2   Ready    <none>                 4m40s   v1.23.1
node-3   Ready    <none>                 4m46s   v1.23.1
  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值