searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

k8s安装及openyurt转换

2023-06-15 10:14:06
20
0

环境说明

  1.   k8s集群版本: v1.18.9
  2.   docker 版本: 19.3.15
  3.   linux系统:CentOS Linux 8 (Core)  
  4.  机器节点: master-1、master-2、master-3,  本文档以master-1为master节点,将master-2、master-3作为node节点加入k8s集群,最后将k8s集群转为openyurt集群
  5. centos 使用 aliyun: sed -i '/mirrorlist=/d;s|#baseurl=http://mirror.centos.org/$contentdir/$releasever|baseurl=https://mirrors.aliyun.com/$contentdir/$releasever-stream|g' /etc/yum.repos.d/CentOS-*
  6. openyurt集群:v0.6.0 

Docker安装

1.  添加docker-ce镜像源 ( vi /etc/yum.repos.d/docker-ce.repo )

[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

2.  安装docker, 并添加配置文件

#查看可用docker版本
yum list docker-ce --showduplicates | sort -r
#安装docker
yum update && yum install -y docker-ce-19.03.15-3.el8 docker-ce-cli-19.03.15-3.el8  containerd.io-1.4.12
#开机启动docker
systemctl enable docker --now
#/etc/docker/daemon配置文件
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "log-driver": "json-file",
  "log-opts": {"max-size": "100m", "max-file": "3"},
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
#重启docker
systemctl daemon-reload
systemctl restart docker

kube*安装

1.  添加k8s镜像源 ( vi /etc/yum.repos.d/Kubernetes.repo)

[Kubernetes]
baseurl = http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled = 1
gpgcheck = 0
gpgkey = http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
name = kubernetes
repo_gpgcheck = 0

2. 基础环境设置

#设置机器名
hostnamectl set-hostname master-2
# 将 SELinux 设置为 permissive 模式(相当于将其禁用)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
#关闭swap
swapoff -a  
sed -ri 's/.*swap.*/#&/' /etc/fstab

#允许 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


#重启
sysctl --system

#关闭防火墙
systemctl disable firewalld --now

3. kube*安装,并启动kubelet

#安装kube
yum install -y kubelet-1.18.9 kubeadm-1.18.9 kubectl-1.18.9 --disableexcludes=kubernetes
#启动kubelet
systemctl enable --now kubelet

kubeadm初始化master1节点

#1.初始化,其中xxxxx代表master-1节点内网IP,yyyy为外部IP,zzz可以是域名
kubeadm init --apiserver-advertise-address=xxxx --control-plane-endpoint=yyyy --image-repository ehub.ctcdn.cn/eck --kubernetes-version v1.18.9 --service-cidr=10.96.0.0/16 --pod-network-cidr=10.244.0.0/16 --apiserver-cert-extra-sans=yyyy,zzzz --v=5
#2.执行成功后按照提示执行
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
#3.部署网络插件flannel(flannel文件可在官方下载后做相应修改,如镜像拉取地址等) https://github.com/flannel-io/flannel/blob/release/v0.14.1/Documentation/kube-flannel.yml 版本要对应
kubectl apply -f ./flannel.yaml
#4.完成后可以通过kubectl get node -A 查看集群内已加入master-1节点,且状态为ready

kubeadm将node节点加入集群

#1.在master-1机器获取加入集群token
kubeadm token create  --print-join-command
输出: kubadm join  xxxxxx(集群url) --token xxxxxx(bootstrap-secret)  --discovery-token-ca-cert-hash  sha256:xxxxxx(sha256加密算法字符串)
#2.在master-1集群获取证书
kubeadm init phase upload-certs --upload-certs
输出:xxxxxx(certificate key)
#3.执行加入master节点命令
kubadm join  xxxxxx(集群url) --token xxxxxx(bootstrap-secret)  --discovery-token-ca-cert-hash  sha256:xxxxxx(sha256加密算法字符串)  --control-plane  --certificate-key xxxxxx(certificate key)
#4.加入后可以在master-1节点看到集群内的节点
kubectl get node -A

k8s转换为openyurt

#使用yurtctl将k8s转换为openyurt 注意节点名和tunel server的地址
./yurtctl convert --provider kubeadm --cloud-nodes master-1,master-2,master-3 -t -e \
--kubeadm-conf-path /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf \
--yurthub-healthcheck-timeout 5m \
--yurt-controller-manager-image ehub.ctcdn.cn/eck/openyurt/yurt-controller-manager:v0.6.0 \
--yurt-tunnel-agent-image ehub.ctcdn.cn/eck/openyurt/yurt-tunnel-agent:v0.6.0 \
--yurt-tunnel-server-image ehub.ctcdn.cn/eck/openyurt/yurt-tunnel-server:v0.6.0 \
--yurt-app-manager-image ehub.ctcdn.cn/eck/openyurt/yurt-app-manager:v0.5.0 \
--node-servant-image ehub.ctcdn.cn/eck/openyurt/node-servant:v0.6.0 \
--yurt-tunnel-server-address yyyy:31008 \
--yurthub-image ehub.ctcdn.cn/eck/openyurt/yurthub:v0.6.0


echo "更改kube-proxy的设置,确保边缘节点的kubeproxy能连上中心"
kubectl annotate service kube-dns -n kube-system openyurt.io/topologyKeys=openyurt.io/nodepool

kubectl get cm -n kube-system kube-proxy -o jsonpath="{.data.config\.conf}" > config.conf && \
  sed -i '/kubeconfig: \/var\/lib\/kube-proxy\/kubeconfig.conf/d' config.conf && \
  kubectl get cm -n kube-system kube-proxy -o jsonpath="{.data.kubeconfig\.conf}" > kubeconfig.conf && \
  kubectl create configmap kube-proxy --from-file config.conf --from-file kubeconfig.conf -n kube-system -o yaml --dry-run=client | kubectl replace -f - && \
  rm -f config.conf && rm -f kubeconfig.conf && kubectl delete pods -l k8s-app=kube-proxy -n kube-system
0条评论
作者已关闭评论
张****强
6文章数
1粉丝数
张****强
6 文章 | 1 粉丝
原创

k8s安装及openyurt转换

2023-06-15 10:14:06
20
0

环境说明

  1.   k8s集群版本: v1.18.9
  2.   docker 版本: 19.3.15
  3.   linux系统:CentOS Linux 8 (Core)  
  4.  机器节点: master-1、master-2、master-3,  本文档以master-1为master节点,将master-2、master-3作为node节点加入k8s集群,最后将k8s集群转为openyurt集群
  5. centos 使用 aliyun: sed -i '/mirrorlist=/d;s|#baseurl=http://mirror.centos.org/$contentdir/$releasever|baseurl=https://mirrors.aliyun.com/$contentdir/$releasever-stream|g' /etc/yum.repos.d/CentOS-*
  6. openyurt集群:v0.6.0 

Docker安装

1.  添加docker-ce镜像源 ( vi /etc/yum.repos.d/docker-ce.repo )

[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

2.  安装docker, 并添加配置文件

#查看可用docker版本
yum list docker-ce --showduplicates | sort -r
#安装docker
yum update && yum install -y docker-ce-19.03.15-3.el8 docker-ce-cli-19.03.15-3.el8  containerd.io-1.4.12
#开机启动docker
systemctl enable docker --now
#/etc/docker/daemon配置文件
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "log-driver": "json-file",
  "log-opts": {"max-size": "100m", "max-file": "3"},
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
#重启docker
systemctl daemon-reload
systemctl restart docker

kube*安装

1.  添加k8s镜像源 ( vi /etc/yum.repos.d/Kubernetes.repo)

[Kubernetes]
baseurl = http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled = 1
gpgcheck = 0
gpgkey = http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
name = kubernetes
repo_gpgcheck = 0

2. 基础环境设置

#设置机器名
hostnamectl set-hostname master-2
# 将 SELinux 设置为 permissive 模式(相当于将其禁用)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
#关闭swap
swapoff -a  
sed -ri 's/.*swap.*/#&/' /etc/fstab

#允许 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


#重启
sysctl --system

#关闭防火墙
systemctl disable firewalld --now

3. kube*安装,并启动kubelet

#安装kube
yum install -y kubelet-1.18.9 kubeadm-1.18.9 kubectl-1.18.9 --disableexcludes=kubernetes
#启动kubelet
systemctl enable --now kubelet

kubeadm初始化master1节点

#1.初始化,其中xxxxx代表master-1节点内网IP,yyyy为外部IP,zzz可以是域名
kubeadm init --apiserver-advertise-address=xxxx --control-plane-endpoint=yyyy --image-repository ehub.ctcdn.cn/eck --kubernetes-version v1.18.9 --service-cidr=10.96.0.0/16 --pod-network-cidr=10.244.0.0/16 --apiserver-cert-extra-sans=yyyy,zzzz --v=5
#2.执行成功后按照提示执行
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
#3.部署网络插件flannel(flannel文件可在官方下载后做相应修改,如镜像拉取地址等) https://github.com/flannel-io/flannel/blob/release/v0.14.1/Documentation/kube-flannel.yml 版本要对应
kubectl apply -f ./flannel.yaml
#4.完成后可以通过kubectl get node -A 查看集群内已加入master-1节点,且状态为ready

kubeadm将node节点加入集群

#1.在master-1机器获取加入集群token
kubeadm token create  --print-join-command
输出: kubadm join  xxxxxx(集群url) --token xxxxxx(bootstrap-secret)  --discovery-token-ca-cert-hash  sha256:xxxxxx(sha256加密算法字符串)
#2.在master-1集群获取证书
kubeadm init phase upload-certs --upload-certs
输出:xxxxxx(certificate key)
#3.执行加入master节点命令
kubadm join  xxxxxx(集群url) --token xxxxxx(bootstrap-secret)  --discovery-token-ca-cert-hash  sha256:xxxxxx(sha256加密算法字符串)  --control-plane  --certificate-key xxxxxx(certificate key)
#4.加入后可以在master-1节点看到集群内的节点
kubectl get node -A

k8s转换为openyurt

#使用yurtctl将k8s转换为openyurt 注意节点名和tunel server的地址
./yurtctl convert --provider kubeadm --cloud-nodes master-1,master-2,master-3 -t -e \
--kubeadm-conf-path /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf \
--yurthub-healthcheck-timeout 5m \
--yurt-controller-manager-image ehub.ctcdn.cn/eck/openyurt/yurt-controller-manager:v0.6.0 \
--yurt-tunnel-agent-image ehub.ctcdn.cn/eck/openyurt/yurt-tunnel-agent:v0.6.0 \
--yurt-tunnel-server-image ehub.ctcdn.cn/eck/openyurt/yurt-tunnel-server:v0.6.0 \
--yurt-app-manager-image ehub.ctcdn.cn/eck/openyurt/yurt-app-manager:v0.5.0 \
--node-servant-image ehub.ctcdn.cn/eck/openyurt/node-servant:v0.6.0 \
--yurt-tunnel-server-address yyyy:31008 \
--yurthub-image ehub.ctcdn.cn/eck/openyurt/yurthub:v0.6.0


echo "更改kube-proxy的设置,确保边缘节点的kubeproxy能连上中心"
kubectl annotate service kube-dns -n kube-system openyurt.io/topologyKeys=openyurt.io/nodepool

kubectl get cm -n kube-system kube-proxy -o jsonpath="{.data.config\.conf}" > config.conf && \
  sed -i '/kubeconfig: \/var\/lib\/kube-proxy\/kubeconfig.conf/d' config.conf && \
  kubectl get cm -n kube-system kube-proxy -o jsonpath="{.data.kubeconfig\.conf}" > kubeconfig.conf && \
  kubectl create configmap kube-proxy --from-file config.conf --from-file kubeconfig.conf -n kube-system -o yaml --dry-run=client | kubectl replace -f - && \
  rm -f config.conf && rm -f kubeconfig.conf && kubectl delete pods -l k8s-app=kube-proxy -n kube-system
文章来自个人专栏
ctyun-zhangq
6 文章 | 1 订阅
0条评论
作者已关闭评论
作者已关闭评论
0
0