前言:
望大家可以跟着我的走,我将自己踩的坑都会一一说出来,尽量为大家 踩出一条没有荆棘的路,有问题大家可以留言和私信我会一一解答,我不是大神就是一个学习小伙汁,那么接下来让我们开始
安装步骤
建议使用阿里云的服务器
- 首先开通三个2核2G的ECS云服务器(按量付费)
- 安装Kubernetes
- 安装KubeSphere前置环境
- 安装KubeSphere
以下的都需要在三台服务器都进行执行
一、开通云服务器-跟着我的步骤来
至于这里为什么要用 172.31.0.0/16 后面我会说的 别急哈 跟着我来
弄完这一步后就去创建云服务器
记得一定要加入专有网络和分配IPv4的地址
二、安装Docker
1、配置yum源
sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
2、安装docker-(使用固定版本的docker)
sudo yum install -y docker-ce-20.10.7 docker-ce-cli-20.10.7 containerd.io-1.4.6
3、配置docker开机自启动
systemctl enable docker --now
4、配置加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://3nk2zp95.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
三、K8S部署-基础环境
1、设置三台机器的自己的域名
#主节点 将地址换成自己的三台机器的私网地址
cat >> /etc/hosts << EOF
172.31.0.93 Kubernetes-Master
172.31.0.91 Kubernetes-Node1
172.31.0.92 Kubernetes-Node2
EOF
#主从节点
hostnamectl set-hostname k8s-Master
hostnamectl set-hostname k8s-Node1
hostnamectl set-hostname k8s-Node2
2、将 SELinux 设置为 permissive 模式和关闭swap
# 将 SELinux 设置为 permissive 模式(相当于将其禁用)
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
#关闭swap
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab
3、iptables 检查桥接流量
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
4、安装kubelet、kubeadm、kubectl
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF
sudo yum install -y kubelet-1.20.9 kubeadm-1.20.9 kubectl-1.20.9 --disableexcludes=kubernetes
sudo systemctl enable --now kubelet
5、使用kubeadm引导集群-下载各个机器需要的镜像
sudo tee ./images.sh <<-'EOF'
#!/bin/bash
images=(
kube-apiserver:v1.20.9
kube-proxy:v1.20.9
kube-controller-manager:v1.20.9
kube-scheduler:v1.20.9
coredns:1.7.0
etcd:3.4.13-0
pause:3.2
)
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/$imageName
done
EOF
chmod +x ./images.sh && ./images.sh
注意了这里是主节点了
6、初始化主节点
为什么要使用172.31.0.0/16呢是为了保证网络范围不重叠,后面你就会发现的
#所有机器添加master域名映射,以下需要修改为自己的私网地址
echo "172.31.0.93 master" >> /etc/hosts
#主节点初始化
kubeadm init \
--apiserver-advertise-address=172.31.0.93 \
--control-plane-endpoint=master \
--image-repository registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images \
--kubernetes-version v1.20.9 \
--service-cidr=10.96.0.0/16 \
--pod-network-cidr=192.168.0.0/16
7、初始化节点后会返回这个
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/
You can now join any number of control-plane nodes by copying certificate authorities
and service account keys on each node and then running the following as root:
kubeadm join master:6443 --token 421tuf.qu1z0q8920g2z0b2 \
--discovery-token-ca-cert-hash sha256:3ac62298006170b49028bb319ac6ed3489d7a477df392a139bf1e1c50256a58d \
--control-plane
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join master:6443 --token 421tuf.qu1z0q8920g2z0b2 \
--discovery-token-ca-cert-hash sha256:3ac62298006170b49028bb319ac6ed3489d7a477df392a139bf1e1c50256a58d
8、主节点-对照上面初始化返回的内容
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
9、在node1 node2节点-对照上面初始化返回的内容
kubeadm join master:6443 --token 421tuf.qu1z0q8920g2z0b2 \
--discovery-token-ca-cert-hash sha256:3ac62298006170b49028bb319ac6ed3489d7a477df392a139bf1e1c50256a58d
10、安装网络组件-主节点
一定要使用v3.8版本的-才不会报错
都是实践说多了都是泪
curl https://docs.projectcalico.org/v3.8/manifests/calico.yaml -O
#按照顺序来输入
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
source ~/.bash_profile
kubectl apply -f calico.yaml
10、接下来就等带完成之后使用这些命令来查看
#查看集群所有节点
kubectl get nodes
#根据配置文件,给集群创建资源
kubectl apply -f xxxx.yaml
#查看集群部署了哪些应用?
docker ps === kubectl get pods -A
# 运行中的应用在docker里面叫容器,在k8s里面叫Pod
kubectl get pods -A
记得在主节点运行 kubectl get nodes 命令查看 node1 node2 是否是ready的状态
三、到此结束了 ,后面我们来做web平台的搭建
目录
2、将 SELinux 设置为 permissive 模式和关闭swap
标签:kubectl,Kubernetes,--,sudo,etc,docker,K8S,安装,节点 From: https://blog.csdn.net/m0_67520017/article/details/143482443