一、基础环境配置

1.1 关闭防火墙

systemctl stop firewalld && systemctl disable firewalld

1.2 关闭selinux

sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
setenforce 0 # 临时

在这里插入图片描述

1.3 关闭swap

# 临时
swapoff -a
# 永久
echo vm.swappiness=0 >> /etc/sysctl.conf
sysctl -p

1.4 关设置主机名

hostname   # 查看本机hostname
hostnamectl set-hostname k8s-master # 把本机名设置成k8s-master
hostnamectl status  # 查看修改结果

在这里插入图片描述

1.5 添加hosts

echo "127.0.0.1 $(hostname)" >> /etc/hosts  # 修改hosts文件

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

在这里插入图片描述

二、安装及配置Docker

2.1 安装Docker

yum install wget -y
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce
systemctl enable docker && systemctl start docker

2.2 配置Docker

cat > /etc/docker/daemon.json << EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"registry-mirrors": ["https://vydiw6v2.mirror.aliyuncs.com"]
}
EOF
systemctl restart docker

在这里插入图片描述

三、安装kubeadm,kubelet和kubectl

3.1 添加阿里yum源

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
sudo yum install -y kubelet-1.23.0 kubeadm-1.23.0 kubectl-1.23.0 --disableexcludes=kubernetes
sudo systemctl enable --now kubelet

3.2 查看kubelet状态

systemctl status kubelet 

在这里插入图片描述

通过journalctl制定上图的PID进行查看

 journalctl _PID=955 | vim -

在这里插入图片描述

此时需初始化master,请进行3.3 步骤操作。

3.3 初始化master

查看网络IP

在这里插入图片描述

执行初始化

kubeadm init \
--apiserver-advertise-address=10.0.24.12 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.23.0 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16 \
--ignore-preflight-errors=all

注意事项:

  • 修改apiserver-advertise-address为自己的master节点IP

在这里插入图片描述
在这里插入图片描述

按照提示进行操作:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
vi /etc/profile
export KUBECONFIG=/etc/kubernetes/admin.conf
source /etc/profile

3.4 集群检查

kubectl get pod -A

在这里插入图片描述

3.4.1 0/1 nodes are available: 1 node(s) had taint

kubectl describe pod coredns-6d8c4cb4d-52p88 -n kube-system

在这里插入图片描述

警告详情:

  Warning  FailedScheduling  16s (x10 over 10m)  default-scheduler  0/1 nodes are available: 1 node(s) had taint {node.kubernetes.io/not-ready: }, that the pod didn't tolerate.

原因:当创建单机版的 k8s 时,这个时候 master 节点是默认不允许调度 pod

解决方案:直接删除master节点的污点设置

kubectl taint nodes --all node-role.kubernetes.io/master-

在这里插入图片描述

然后就可以正常创建pod

kubectl get nodes

在这里插入图片描述

3.4.2 Unable to update cni config: no networks found in /etc/cni/net.d

systemctl status kubelet

在这里插入图片描述

异常详情:

May 17 16:41:20 k8s-master kubelet[3536]: E0517 16:41:20.156256    3536 kubelet.go:2347] "Container runtime network not ready" networkReady="NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin i...ig uninitialized"
May 17 16:41:22 k8s-master kubelet[3536]: I0517 16:41:22.946145    3536 cni.go:240] "Unable to update cni config" err="no networks found in /etc/cni/net.d"

原因:有安装网络插件,导致corednsPending状态

官网介绍:https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/troubleshooting-kubeadm/

解决方案:下载 kube-flannel.yml进行安装

  • 安装Calico网络插件
#下载yaml文件
curl https://docs.projectcalico.org/manifests/calico.yaml -O

#使用kubectl apply应用刚刚下载好的calico.yaml文件。
kubectl apply -f calico.yaml

#查看当前k8s集群得pods
kubectl get pods -o wide -n kube-system
  • 安装kube-flannel网络插件
#下载yaml文件
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

#使用kubectl apply应用刚刚下载好的calico.yaml文件。
kubectl apply -f kube-flannel.yml

#查看当前k8s集群的pods(一个pod内运行了多个docker容器,-n表命名空间)
kubectl get pods -o wide -n kube-system

在这里插入图片描述

kubectl get pods -n kube-system

在这里插入图片描述

此时查看集群节点状态

kubectl get nodes

在这里插入图片描述

四、安装

4.1 执行 Kuboard v3K8S 中的安装

kubectl apply -f https://addons.kuboard.cn/kuboard/kuboard-v3.yaml
# 您也可以使用下面的指令,唯一的区别是,该指令使用华为云的镜像仓库替代 docker hub 分发 Kuboard 所需要的镜像
# kubectl apply -f https://addons.kuboard.cn/kuboard/kuboard-v3-swr.yaml

参照官网地址:https://kuboard.cn/install/v3/install-in-k8s.html#%E5%AE%89%E8%A3%85

等待 Kuboard v3 就绪,执行指令 watch kubectl get pods -n kuboard,等待 kuboard 名称空间中所有的 Pod 就绪,如下所示:

在这里插入图片描述

[root@VM-24-12-centos ~]# kubectl get pods -n kuboard
NAME                               READY   STATUS    RESTARTS        AGE
kuboard-agent-2-5c5f64fbbb-8scbk   1/1     Running   0               2m37s
kuboard-agent-7cf96956c8-wjnjs     1/1     Running   1 (2m11s ago)   2m37s
kuboard-etcd-7k8mw                 1/1     Running   0               3m36s
kuboard-questdb-77f4c698cc-2w5jq   1/1     Running   0               2m36s
kuboard-v3-56b4b954c9-72kqh        1/1     Running   0               3m36s
[root@VM-24-12-centos ~]# kubectl describe pod kuboard-v3-56b4b954c9-72kqh -n kuboard
Name:         kuboard-v3-56b4b954c9-72kqh
Namespace:    kuboard
Priority:     0
Node:         k8s-master/10.0.24.12
Start Time:   Tue, 17 May 2022 17:05:23 +0800
Labels:       k8s.kuboard.cn/name=kuboard-v3
              pod-template-hash=56b4b954c9
Annotations:  <none>
Status:       Running
IP:           10.244.0.4
IPs:
  IP:           10.244.0.4
Controlled By:  ReplicaSet/kuboard-v3-56b4b954c9
Containers:
  kuboard:
    Container ID:   docker://8f7928f326027e1b227d45f22b648aade2f075d38a970fecb6dd76092fe06e05
    Image:          eipwork/kuboard:v3
    Image ID:       docker-pullable://eipwork/kuboard@sha256:0ea7d38afa2bb31ae178f8dc32feeccd480376097a2e3b7423750d02f123fa8c
    Ports:          80/TCP, 443/TCP, 10081/TCP, 10081/UDP
    Host Ports:     0/TCP, 0/TCP, 0/TCP, 0/UDP
    State:          Running
      Started:      Tue, 17 May 2022 17:06:04 +0800
    Ready:          True
    Restart Count:  0
    Liveness:       http-get http://:80/kuboard-resources/version.json delay=30s timeout=1s period=10s #success=1 #failure=3
    Readiness:      http-get http://:80/kuboard-resources/version.json delay=30s timeout=1s period=10s #success=1 #failure=3
    Environment Variables from:
      kuboard-v3-config  ConfigMap  Optional: false
    Environment:
      HOSTIP:     (v1:status.hostIP)
      HOSTNAME:   (v1:spec.nodeName)
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-zl646 (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  kube-api-access-zl646:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node-role.kubernetes.io/master op=Exists
                             node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  3m40s  default-scheduler  Successfully assigned kuboard/kuboard-v3-56b4b954c9-72kqh to k8s-master
  Normal  Pulling    3m39s  kubelet            Pulling image "eipwork/kuboard:v3"
  Normal  Pulled     2m59s  kubelet            Successfully pulled image "eipwork/kuboard:v3" in 39.749208341s
  Normal  Created    2m59s  kubelet            Created container kuboard
  Normal  Started    2m59s  kubelet            Started container kuboard
[root@VM-24-12-centos ~]# 

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐