操作系统:Loongnix Server 8.4

# su root

//iptables设置
# iptables -F && iptables -X && iptables -Z && iptables -L&&systemctl
stop iptables

//关闭交换分区: 
# swapoff -a;sed -i -e /swap/d /etc/fstab

//关闭selinux分区:
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# setenforce 0

//修改主机名
# echo "master" >/etc/hostname
# hostnamectl --static set-hostname master

//获取本机IP
# IP=`ip a | grep -w "inet" | grep -v 127 | sed 's/^[ \t]*//g' | cut -d ' ' -f2 | awk -F"/" '{print $1}'`

//添加host
# echo $IP master001 >> /etc/hosts

# yum -y install loongnix-release-kubernetes.noarch
# yum -y install loongnix-release-epel.noarch

# yum -y install kubelet kubeadm kubectl
# yum -y install supervisor
# yum -y install tcp_wrappers-libs
# systemctl enable kubelet.service

# yum -y install docker-ce
# systemctl enable docker

# kubeadm config print init-defaults > init_default.yaml
//找到对应配置,修改为以下内容
localAPIEndpoint:
advertiseAddress: 10.130.0.125(master的主机IP)
bindPort: 6443
........
imageRepository: loongnixk8s(私有仓库地址)
kind: ClusterConfiguration
kubernetesVersion: v1.20.0(当前k8s版本)
networking:
dnsDomain: cluster.local


// 查看当前环境所需要的镜像列表: 
# kubeadm config images list --config init_default.yaml 
mirrorloongsoncontainers/kube-apiserver:v1.20.0
mirrorloongsoncontainers/kube-controller-manager:v1.20.0
mirrorloongsoncontainers/kube-scheduler:v1.20.0
mirrorloongsoncontainers/kube-proxy:v1.20.0
mirrorloongsoncontainers/pause:3.2
mirrorloongsoncontainers/etcd:3.4.13-0
mirrorloongsoncontainers/coredns:1.7.0


// 拉取镜像,并对现有镜像改名
# ./kubernetes.sh

// 通过以下命令获取官方calico配置文件
# curl https://docs.projectcalico.org/archive/v3.18/manifests/calico.yaml -O

//master节点初始化
# kubeadm init --config=init_default.yaml

# echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profile
# source /etc/profile

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

//然后查看node情况:
# kubectl get nodes
NAME     STATUS     ROLES                  AGE     VERSION
master   NotReady   control-plane,master   2m13s   v1.20.0
//此时发现时 NotReady ,接着执行下面的步骤。

# kubectl get pods --all-namespaces -o wide
NAMESPACE     NAME                             READY   STATUS    RESTARTS   AGE     IP            NODE     NOMINATED NODE   READINESS GATES
kube-system   coredns-54c5b9f9dd-5hlxq         0/1     Pending   0          4m39s   <none>        <none>   <none>           <none>
kube-system   coredns-54c5b9f9dd-5q2kk         0/1     Pending   0          4m39s   <none>        <none>   <none>           <none>
kube-system   etcd-master                      1/1     Running   0          4m39s   10.120.1.23   master   <none>           <none>
kube-system   kube-apiserver-master            1/1     Running   0          4m39s   10.120.1.23   master   <none>           <none>
kube-system   kube-controller-manager-master   1/1     Running   0          4m39s   10.120.1.23   master   <none>           <none>
kube-system   kube-proxy-cb7m6                 1/1     Running   0          4m40s   10.120.1.23   master   <none>           <none>
kube-system   kube-scheduler-master            1/1     Running   0          4m39s   10.120.1.23   master   <none>           <none>

//此时发现coredns pod处于 ContainerCreating状态
//配置环境变量: 
# export KUBECONFIG=/etc/kubernetes/admin.conf

//master上部署k8s网络组件calico操作
# kubectl create -f calico.yaml
configmap/calico-config created
customresourcedefinition.apiextensions.k8s.io/bgpconfigurations.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/bgppeers.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/blockaffinities.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/clusterinformations.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/felixconfigurations.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/globalnetworkpolicies.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/globalnetworksets.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/hostendpoints.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/ipamblocks.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/ipamconfigs.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/ipamhandles.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/ippools.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/kubecontrollersconfigurations.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/networkpolicies.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/networksets.crd.projectcalico.org created
clusterrole.rbac.authorization.k8s.io/calico-kube-controllers created
clusterrolebinding.rbac.authorization.k8s.io/calico-kube-controllers created
clusterrole.rbac.authorization.k8s.io/calico-node created
clusterrolebinding.rbac.authorization.k8s.io/calico-node created
daemonset.apps/calico-node created
serviceaccount/calico-node created
deployment.apps/calico-kube-controllers created
serviceaccount/calico-kube-controllers created
poddisruptionbudget.policy/calico-kube-controllers created


# kubectl get pods --all-namespaces -o wide
NAMESPACE     NAME                                       READY   STATUS    RESTARTS   AGE     IP               NODE        NOMINATED NODE   READINESS GATES
kube-system   calico-kube-controllers-6dd44d4956-dgtgw   1/1     Running   0          2m55s   192.168.163.65   master001   <none>           <none>
kube-system   calico-node-wq2j4                          1/1     Running   0          2m55s   10.120.1.23      master001   <none>           <none>
kube-system   coredns-54c5b9f9dd-665hj                   1/1     Running   0          7m18s   192.168.163.66   master001   <none>           <none>
kube-system   coredns-54c5b9f9dd-7fbtd                   1/1     Running   0          7m18s   192.168.163.67   master001   <none>           <none>
kube-system   etcd-master001                             1/1     Running   0          7m15s   10.120.1.23      master001   <none>           <none>
kube-system   kube-apiserver-master001                   1/1     Running   0          7m16s   10.120.1.23      master001   <none>           <none>
kube-system   kube-controller-manager-master001          1/1     Running   0          7m16s   10.120.1.23      master001   <none>           <none>
kube-system   kube-proxy-dhdbd                           1/1     Running   0          7m18s   10.120.1.23      master001   <none>           <none>
kube-system   kube-scheduler-master001                   1/1     Running   0          7m16s   10.120.1.23      master001   <none>           <none>

# kubectl get nodes
NAME        STATUS   ROLES                  AGE    VERSION
master001   Ready    control-plane,master   8m5s   v1.20.0

kubernetes.sh 的内容如下:

docker pull cr.loongnix.cn/calico/node:3.18.0
docker pull cr.loongnix.cn/calico/cni:3.18.0
docker pull cr.loongnix.cn/calico/pod2daemon-flexvol:3.18.0
docker pull cr.loongnix.cn/calico/kube-controllers:3.18.0

docker pull cr.loongnix.cn/kubernetes/kube-apiserver:v1.20.0
docker pull cr.loongnix.cn/kubernetes/kube-controller-manager:v1.20.0
docker pull cr.loongnix.cn/kubernetes/kube-proxy:v1.20.0
docker pull cr.loongnix.cn/kubernetes/kube-scheduler:v1.20.0

docker pull cr.loongnix.cn/kubernetes/pause:3.2
#docker pull cr.loongnix.cn/coredns:1.8.0
docker pull cr.loongnix.cn/coredns:1.7.0
docker pull cr.loongnix.cn/kubernetes/etcd:3.4.13-0

docker tag cr.loongnix.cn/kubernetes/kube-apiserver:v1.20.0 mirrorloongsoncontainers/kube-apiserver:v1.20.0
docker tag cr.loongnix.cn/kubernetes/kube-controller-manager:v1.20.0 mirrorloongsoncontainers/kube-controller-manager:v1.20.0
docker tag cr.loongnix.cn/kubernetes/kube-scheduler:v1.20.0 mirrorloongsoncontainers/kube-scheduler:v1.20.0
docker tag cr.loongnix.cn/kubernetes/kube-proxy:v1.20.0 mirrorloongsoncontainers/kube-proxy:v1.20.0
docker tag cr.loongnix.cn/kubernetes/pause:3.2 mirrorloongsoncontainers/pause:3.2
docker tag cr.loongnix.cn/kubernetes/etcd:3.4.13-0 mirrorloongsoncontainers/etcd:3.4.13-0
#docker tag cr.loongnix.cn/coredns:1.8.0 mirrorloongsoncontainers/coredns:1.8.0
docker tag cr.loongnix.cn/coredns:1.7.0 mirrorloongsoncontainers/coredns:1.7.0

清理k8s 环境的脚本如下:
make-clean.sh

#!/bin/bash

###########################################
###Clean up the environment on master
###########################################

kubeadm reset
rm -rf /var/etcd
rm -rf /var/lib/kubelet/
rm -rf /run/kubernetes/
rm $HOME/.kube -rf
iptables -F && iptables -X && iptables -Z && iptables -L&&systemctl stop iptables&&systemctl status iptables
systemctl stop firewalld
swapoff -a;sed -i -e /swap/d /etc/fstab
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

参考:
http://doc.loongnix.cn/web/#/71?page_id=232
https://blog.csdn.net/weixin_45531306/article/details/121419041

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐