云原生扫盲

本文详细介绍了云原生的概念和实践,包括Kubernetes的组件、工作原理、服务部署,以及Docker的容器化应用。还探讨了KubeSphere平台的安装和使用,展示了如何在KubeSphere中部署中间件和微服务,以及DevOps的最佳实践。此外,文章提到了Kubernetes的存储抽象、服务发现、持久化卷和Ingress等关键概念。
摘要由CSDN通过智能技术生成

【强制】云原生。

在云计算环境中构建、部署和管理现代应用程序的软件方法。

【参考】尚硅谷云原生课程。

课程链接:https://www.bilibili.com/video/BV13Q4y1C7hS/

课程简介:从零开始,以实战的方式,把云原生的整套周边快速地玩儿起来。

前置要求:了解Linux、Nginx、MySQL、Redis等。 

1 云服务器

【推荐】公有云和私有云。

1) 公有云。

    公有云资源(例如服务器和存储空间)由第三方云服务提供商拥有和运营,这些资源通过Internet提供。

    国内的云服务提供商有:阿里云、腾讯云等。

    公有云的优势:成本低、高可靠性、无需维护、近乎无限制的缩放性。

2) 私有云。

    私有云由专供一个企业或组织使用的云计算资源构成。在私有云中,服务和基础结构始终在私有网络上进行维护,软件和硬件专供组织使用。这样,私有云可以使组织更加方便地自定义资源,从而满足特定的IT需求。

《浪潮之巅》中鄙视了将云分为公有云和私有云的行为:

“云计算的初衷是整合社会的计算资源,达到节省资源的效果。为了达到这个效果,每个云计算提供商要有相当的规模。现在很多外行,以及涉及自身利益揣着明白装糊涂的内行,以所谓私有云的名义,将本该合并的服务硬是划成了豆腐块。在美国科技界,大家的共识是云计算基础设施的提供商数量只能是个位数的。而在中国,这个道理讲不通,因为所有零敲碎打的公司和政府部门都以‘你讲的那是公有云,我们也需要私有云’为借口划分地盘。岂不知,即使Google这家计算能力全球最大的公司,也不过是一块私有云而已,因为私有云并不意味着规模小。……在中国有些人也很清楚云计算不是谁都能搞的,但这是提升GDP和业绩的最好名头,一定要用一下。于是,云计算的泡沫就越吹越大了。”

【参考】购买云服务器(阿里云)。

1) 注册并登录阿里云。

    https://www.aliyun.com/

2) 选择云服务器ECS服务,创建实例。

    基础配置:按量付费、1G内存、CentOS镜像。

    网络和安全组:分配公网IPv4地址。

    系统配置:设置登录密码和服务器名称。

    创建完成。

3) 使用Electerm、XShell等工具,通过公网IP连接云服务器。

4) 测试安装Nginx。

yum install nginx
systemctl start nginx

    复制公网IP,打开浏览器访问 公网IP(Nginx默认监听80端口),即可访问Nginx。

【强制】安全组。

通过设置安全组规则,我们可以限制外部访问云服务器的端口范围。

【推荐】专有网络(VPC)。

1) 划分网段。

    192.168.0.0/16

2) 创建交换机。

    switch1:192.168.0.0/24

    switch2:192.168.1.0/24

3) 创建云服务器实例时,可以选择专有网络和交换机。

2 Docker

2.1 Docker简介

【强制】虚拟化和容器化。

1) 虚拟化。

    虚拟技术是一种通过组合或分区现有的计算机资源(CPU、内存、磁盘空间等),使得这些资源表现为一个或多个操作环境,从而提供优于原有资源配置的访问方式的技术。虚拟化就是把物理资源转变为逻辑上可以管理的资源,以打破物理结构之间的壁垒。

    虚拟化的优点:隔离性强。

2) 容器化。

    容器化是指将软件代码和所需的所有组件(例如库、框架和其他依赖项)打包在一起,让它们隔离在自己的“容器”中。这样,容器内的软件或应用就可以在任何环境和任何基础架构上一致地移动和运行,不受该环境或基础架构的操作系统影响。

    Linux实现了容器化,Docker对此功能进行了封装。

    容器化的优点:隔离性强、秒级启动、可移植性好。

【推荐】Docker架构图。

Client:客户端。

DOCKER_HOST:安装Docker的主机。

Registry:仓库,Docker Hub。

Docker daemon:Docker后台进程。

Images:镜像,只读的文件系统,可以简单地理解为应用程序。

Containers:容器,隔离应用和周围的环境。

2.2 Docker安装与使用

【参考】Docker安装。

1) 使用青云创建云服务器。

    https://www.qingcloud.com/

2) 安装Docker。

​yum remove docker*
yum install -y yum-utils

yum-config-manager --add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum install -y docker-ce-20.10.7 docker-ce-cli-20.10.7 containerd.io-1.4.6

systemctl enable docker --now

# 配置容器镜像加速器
# 加速器地址可在 阿里云-容器镜像服务-镜像加速器 页面获取
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://82m9ar63.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

【推荐】镜像相关操作。

# 下载Nginx镜像
# docker pull 镜像名:版本号
# 如果不加版本号,默认下载最新版
docker pull nginx

# 查看本地镜像
docker images

# 移除镜像
# 镜像ID可以通过docker images命令查看
# docker rmi 镜像名:版本号/镜像ID

# 创建容器,将镜像作为应用程序在容器内运行
# -d:后台运行
docker run --name=mynginx -d nginx

# 执行镜像(进入镜像文件系统)
# 容器ID可以通过docker ps命令查看
docker exec -it 容器ID /bin/bash
# 退出
# 容器内 exit

# 本地提交(镜像是只读的,实际上是创建了新的镜像)
docker commit 容器ID testnginx:v1.0
# 下次启动时运行新镜像
# docker run -d -p 88:80 testnginx:v1.0

# 本地镜像打标
docker tag testnginx:v1.0 lalixiaozhu/testnginx:v1.0

# 将本地镜像推送到docker.hub
docker push lalixiaozhu/testnginx:v1.0
# 推送前必须登录docker.hub账号
# docker login,输入用户名和密码
# 镜像推送到docker.hub后,在其他机器上可直接下载
# docker pull lalixiaozhu/testnginx:v1.0

# 保存镜像到本地 -o output
docker save -o testnginx.tar testnginx:v1.0

# 复制镜像
scp testnginx.tar root@192.168.xx.xx:/root/

# 在root@192.168.xx.xx:/root/路径下加载镜像 -i input
docker load -i testnginx.tar

【推荐】容器相关操作。

# 创建容器,将镜像作为应用程序在容器内运行
# -d:后台运行
docker run --name=mynginx -d nginx

# 查看正在运行应用程序的容器
docker ps
# -a:查看所有
docker ps -a

# 移除已停止运行应用程序的容器
docker rm mynginx
# -f 强制移除
docker rm -f mynginx

# 停止运行应用程序
# docker stop 容器名称/容器ID

# 重启应用程序
# docker start 容器名称/容器ID

# 设置应用程序开机自启
# docker update 容器名称/容器ID --restart=always

# 挂载(运行时用主机上的文件代替镜像中的文件)
# -restart=always 设置应用程序开机自启
# -p 80:80:端口映射,从主机的80端口映射到Docker的80端口
# -v 挂载
docker run -d --name=mynginx02 --restart=always -p 80:80 \
-v /data/nginx/html:/usr/share/nginx/html \
-v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
nginx

# 主机上用来挂载的文件不能为空
# echo hello > /data/nginx/html/index.html
# docker cp 容器ID:/etc/nginx/nginx.conf /data/nginx/conf/nginx.conf

# 查看容器日志
# docker logs 容器ID

【推荐】打包Spring Boot应用。

1) 准备一个Spring Boot应用。

    如果没有可用的Spring Boot应用,可进入https://start.spring.io/,选择Maven工程,添加Spring Web、Spring Data Redis依赖。生成,导入IDEA。

    写一个简单的功能。

@RestController
public class HelloWorldController {
    @GetMapping("/hello")
    public String hello() {
        return "Hello World";
    }
}

    启动Spring Boot应用。

    访问localhost:8080/hello,成功展示“Hello World”。

2) 使用Spring Boot打包应用。

    得到一个jar:MyApp-0.0.1-SNAPSHOT.jar。

3) 将jar:MyApp-0.0.1-SNAPSHOT.jar上传到服务器。

4) 在服务器上,在jar:MyApp-0.0.1-SNAPSHOT.jar所在目录下创建Dockerfile。

FROM openjdk:8-jdk-slim
LABEL maintainer=lalixiaozhu
COPY target/*.jar /app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

5) 执行docker build命令

# 注意命令末尾有个点,代表当前目录
# Dockerfile是默认名称,可以不写"-f Dockerfile"
docker build -t myapp:v1.0 -f Dockerfile .

    执行完docker build以后,使用docker images命令可以看到镜像myapp:v1.0。

    接下来只需要运行该镜像,就可以通过公网IP访问了。

docker run -d --name myapp -p 8080:8080 myapp:v1.0

    当然也可以推到docker.hub,供其他服务器下载。

3 Kubernetes

3.1 Kubernetes简介

【强制】Kubernetes。

Kubernetes,又称K8s,一个开源容器编排平台,可以自动完成在部署、管理和扩展容器化应用过程中涉及的许多手动操作。

Kubernetes的特性:

1) 服务发现和负载均衡。

2) 存储编排。

3) 自动部署和回滚。

4) 自动完成装箱计算。

    Kubernetes允许你指定每个容器所需CPU和内存(RAM)。

5) 自我修复。

    Kubernetes重新启动失败的容器、替换容器、杀死不响应用户定义的运行状况检查的容器,并且在准备好服务之前不将其通告给客户端。

6) 密钥与配置管理。

【推荐】Kubernetes架构。

Kubernetes Cluster = N Master Node + N Worker Node:N主节点+N工作节点;N>=1。

1) kube-apiserver。

    kube-apiserver公开了Kubernetes API,是Kubernetes控制面板(Control Plane)的前端。采用外观模式。

2) etcd。

    etcd是兼具一致性和高可用性的键值数据库,可以作为保存Kubernetes所有集群数据的后台数据库。

3) kube-scheduler。

    kube-scheduler负责监视新创建的、未指定运行节点(node)的Pods,选择节点让Pod在上面运行。

4) kube-controller-manager。

    kube-controller-manager是主节点上运行控制器的组件。这些控制器包括:

        节点控制器(Node Controller):负责在节点出现故障时进行通知和响应。

        任务控制器(Job controller):监测代表一次性任务的Job对象,然后创建Pods来运行这些任务直至完成。

        端点控制器(Endpoints Controller):填充端点(Endpoints)对象(即加入Service与Pod)。

        服务帐户和令牌控制器(Service Account & Token Controllers):为新的命名空间创建默认帐户和API访问令牌。

5) cloud-controller-manager。

    cloud-controller-manager是嵌入特定云的控制逻辑的控制平面组件。云控制器管理器允许您链接集群到云提供商的应用编程接口中,并把和该云平台交互的组件与只和您的集群交互的组件分离开。

6) kubelet。

    一个在集群中每个节点(node)上运行的代理。它保证容器(containers)都运行在Pod中。

7) kube-proxy。

    kube-proxy是集群中每个节点上运行的网络代理,实现Kubernetes服务(Service)概念的一部分。

3.2 Kubernetes集群搭建

【参考】Kubernetes集群搭建。

1) 创建专有网络,在专有网络中创建3台云服务器。

    专有网络不要选192.168.0.0/16,可能会和pod-network-cidr冲突。

    安全组要开启内网互信。(默认是开启的)

2) 给每台服务器安装Docker。

3) 给每台服务器进行环境配置。

# (云服务器的默认名称无意义)给每台服务器设置域名
# 示例:k8s-master、node1、node2
hostnamectl set-hostname xxxx

# 将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

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

# 配置k8s的yum源地址
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

# 安装kubelet、kubeadm、kubectl
sudo yum install -y \
kubelet-1.20.9 kubeadm-1.20.9 kubectl-1.20.9 --disableexcludes=kubernetes

# 开机启动kubelet
sudo systemctl enable --now kubelet

# 给每台机器配置master域名
echo "172.31.0.4  k8s-master" >> /etc/hosts

5) 初始化master节点。

# 对master进行初始化
# apiserver-advertise-address=master的IP地址
# control-plane-endpoint=master域名
# service-cidr=10.96.0.0/16 不用改
# pod-network-cidr=192.168.0.0/16 不用改
kubeadm init \
--apiserver-advertise-address=172.31.0.4 \
--control-plane-endpoint=k8s-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

初始化成功后,将下面的信息记录下来备用。

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 k8s-master:6443 --token 3vckmv.lvrl05xpyftbs177 \
    --discovery-token-ca-cert-hash sha256:1dc274fed24778f5c284229d9fcba44a5df11efba018f9664cf5e8ff77907240 \
    --control-plane 

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join k8s-master:6443 --token 3vckmv.lvrl05xpyftbs177 \
    --discovery-token-ca-cert-hash sha256:1dc274fed24778f5c284229d9fcba44a5df11efba018f9664cf5e8ff77907240

7) 将所有worker节点加入集群。

# 从主节点初始化成功信息中复制,token 24小时内有效
kubeadm join k8s-master:6443 --token 3vckmv.lvrl05xpyftbs177 \
    --discovery-token-ca-cert-hash sha256:1dc274fed24778f5c284229d9fcba44a5df11efba018f9664cf5e8ff77907240

# 若token已过期,使用下面的命令
kubeadm token create --print-join-command

8) 给每台服务器安装kube-apiserver、kube-proxy、kube-controller-manager、kube-scheduler、etcd、coredns、pause。(用或不用都可以装上)

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

【推荐】kubectl常用命令。(仅master节点可用)

# 查看集群的所有节点
kubectl get nodes

# 应用配置文件
# 在Kubernetes中,应用配置文件是个十分常用的功能
# 因考虑到篇幅,本文省略了这部分内容
kubectl apply -f xxxx.yaml

【参考】Dashboard。

Dashboard是Kubernetes官方提供的可视化工具。

3.3 Kubernetes核心概念

【强制】Namespace。

命名空间。Namespace用来对资源进行隔离划分。

【推荐】Namespace相关命令。

# 创建Namespace
kubectl create ns hello

# 删除Namespace
kubectl delete ns hello

【强制】Pod。

Pod是运行中的一组容器,是Kubernetes中应用的最小单位。

Kubernetes对Docker container进行封装,成为Pod。

Kubernetes给每个Pod都分配了一个IP地址。

【推荐】Pod相关命令。

# 运行Pod
# 补充:推荐使用Deployment来运行Pod
kubectl run mynginx --image=nginx

# 查看default Namespace中的Pod
# -n 指定Namespace
# -owide 查看更多信息(包括Pod的IP地址)
kubectl get pod

# 查看Pod详情
kubectl describe pod mynginx

# 删除Pod
kubectl delete pod mynginx

# 查看Pod日志
kubectl logs mynginx

【强制】Deployment及其类似概念。

1) Deployment:无状态应用部署,比如微服务,提供多副本等功能。

    Deployment可以控制Pod,使Pod拥有自愈、多副本、扩/锁容等能力。

2) Stateful Set:有状态应用部署,比如Redis,提供稳定的存储、网络等功能。

3) Daemon Set:守护型应用部署,比如日志收集组件,运行在每一台机器上。

4) Job/Cron Job:定时任务部署,比如垃圾清理组件,可以在指定时间运行。

【推荐】Deployment相关命令。

# 创建Deployment
# mytomcat宕机时,自动重新创建mytomcat,即自愈
kubectl create deployment mytomcat --image=tomcat:8.5.68

# 删除Deployment
kubectl delete deploy mytomcat

# 创建Deployment,并创建3份my-dep(3个Pod),即多副本
kubectl create deployment my-dep --image=nginx --replicas=3

# 将my-dep的规模扩大到5份,即扩容
kubectl scale --replicas=5 deployment/my-dep

# 滚动更新
kubectl set image deployment/my-dep nginx=nginx:1.16.1 --record

# 查看回滚状态
kubectl rollout status deployment/my-dep

# 查看历史版本
kubectl rollout history deployment/my-dep

# 查看某个历史版本的详情
kubectl rollout history deployment/my-dep --revision=2

# 回滚(到上个版本)
kubectl rollout undo deployment/my-dep

# 回滚到指定版本
kubectl rollout undo deployment/my-dep --to-revision=2

【强制】Service。

服务。Service是对 一组暴露的Pods组成的网络服务 的抽象。

Kubernetes给每个Service都分配了一个IP地址。

【推荐】Service相关命令。

# 暴露deployment
# --type=ClusterIP 集群内部可访问,默认
kubectl expose deployment my-dep \
--port=8000 --target-port=80 --type=ClusterIP
# --type=NodePort 集群外也可以访问
kubectl expose deployment my-dep \
--port=8000 --target-port=80 --type=NodePort

# 查看service
kubectl get service

# 使用service IP:port可以负载均衡地访问my-dep
curl 10.96.xx.xx:8000
# 使用域名访问(deployment名.namespace名.svc)
curl my-dep.default.svc:8000

【强制】Ingress。

入口。Ingress是Service的统一网关入口。

Kubernetes希望Ingress能够成为集群流量的唯一入口。

3.4 Kubernetes存储抽象

【推荐】NFS-Server。

网络文件系统服务。

【参考】搭建NFS-Server。

1) 在每台服务器安装nfs-utils。

2) 在master节点创建集群文件存储目录/nfs/data/。

# 对外暴露目录
echo "/nfs/data/ *(insecure,rw,sync,no_root_squash)" > /etc/exports
# 创建共享目录
mkdir -p /nfs/data

# 开机启动rpcbind
systemctl enable rpcbind --now
# 开机启动nfs-server
systemctl enable nfs-server --now

# 使配置生效
exportfs -r
# 检查配置是否生效
exportfs

3) worker节点同步master节点。

# 显示master节点可挂载的目录
showmount -e 172.31.0.4

# 创建目录
mkdir -p /nfs/data
# 挂载目录
mount -t nfs 172.31.0.4:/nfs/data /nfs/data

4) 配置默认存储。

    创建配置文件sc.yaml。

vi sc.yaml

    将Kubernetes附录中的sc.yaml粘贴进去,记得修改其中的IP地址。

    应用该配置文件。

kubectl apply -f sc.yaml

# 确认配置是否生效
kubectl get sc

【推荐】PV&PVC。

1) 直接使用NFC挂载的方式存在一些问题。

    每个Pod能使用的存储空间没有限制。

    如果Pod被下线,挂载目录下的数据不会被清理。

2) PV&PVC是上述问题的一种解决方案。

    PV:持久卷(Persistent Volume),将应用需要持久化的数据保存到指定的位置。

    PVC:持久卷申明(Persistent Volume Claim),申明需要使用的持久卷规格。

    提前创建静态的PV池,由每个Pod提供PVC,申明需要使用的持久卷规格,在PV池中寻找合适的PV,与PVC进行绑定。如果Pod被下线,PVC跟着被删除,绑定着的PV将被回收。

【推荐】ConfigMap。

挂载目录可以使用PV&PVC,挂载配置文件推荐使用ConfigMap。

# 创建Redis ConfigMap
kubectl create cm redis-conf --from-file=redis.conf

# 查看Config Map
kubectl get cm redis-conf -oyaml

【参考】Secret。

Secret对象类型用来保存敏感信息,例如密码、OAuth令牌和SSH密钥。将这些信息放在Secret中比放在Pod的定义或者容器镜像中来说更加安全和灵活。

# 创建secret
kubectl create secret docker-registry <Select名称> \
  --docker-server=<你的镜像仓库服务器> \
  --docker-username=<你的用户名> \
  --docker-password=<你的密码> \
  --docker-email=<你的邮箱地址>

# 查看secret
kubectl get secret <Select名称>

4 KubeSphere

【强制】KubeSphere。

KubeSphere是一个全栈的Kubernetes容器云PaaS解决方案。

KubeSphere是基于Kubernetes构建的分布式、多租户、多集群、企业级开源容器平台,具有强大且完善的网络与存储能力,并通过极简的人机交互提供完善的多集群管理、CI/CD、微服务治理、应用管理等功能,帮助企业在云、虚拟化及物理机等异构基础设施上快速构建、部署及运维容器架构,实现应用的敏捷开发与全生命周期管理。

4.1 KubeSphere安装

【参考】KubeSphere安装。

1) 准备云服务器。

    master:1台,CentOS 7.9,4核8G,分配公网IPv4地址。

    worker:2台,CentOS 7.9,8核16G,分配公网IPv4地址。

    按量付费。

2) 安装Docker。

3) 安装k8s。

4) 搭建NFS-Server。

5) 搭建Metrics-Server。

    创建配置文件metrics.yaml。

vi metrics.yaml

    将KubeSphere附录中的metrics.yaml粘贴进去。

    应用该配置文件。

kubectl apply -f metrics.yaml

6) 安装KubeSphere。

    应用KubeSphere附录中的kubesphere-installer.yaml和cluster-configuration.yaml。

# 查看安装日志
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

# 解决etcd监控证书找不到的问题
kubectl -n kubesphere-monitoring-system create secret generic kube-etcd-client-certs  --from-file=etcd-client-ca.crt=/etc/kubernetes/pki/etcd/ca.crt  --from-file=etcd-client.crt=/etc/kubernetes/pki/apiserver-etcd-client.crt  --from-file=etcd-client.key=/etc/kubernetes/pki/apiserver-etcd-client.key

7) 安全组放行30000-32767端口。

8) 访问任意服务器的30880接口。

    默认账号 : admin

    默认密码 : P@88w0rd

4.2 KubeSphere实战

多租户系统

【参考】多租户系统。

用于权限隔离。集群-企业空间-项目。

1) 使用admin账号登录。

    创建一个user-manager。user-manager可以创建其他用户。

2) 使用user-manager账号登录。

    创建一个workspaces-manager。workspaces-manager可以创建工作空间。

    创建N个platform-regular。

3) 使用workspaces-manager账号登录。

    创建一个企业空间。点击进入。

    邀请其他用户成为企业admin。

4) 使用企业admin账号登录。

    邀请其他用户成为企业self-provisioner或企业regular。

5) 使用企业self-provisioner账号登录。

    创建项目。后面的部署行为都发生在项目中。

    邀请其他用户成为项目成员。

KubeSphere部署中间件

【强制】应用部署的三要素。

1) 应用的部署方式。

    无状态/有状态/守护进程。

2) 应用的数据挂载。

    数据、配置文件。

3) 应用的可访问性。

【参考】部署MySQL。

1) 配置中心-创建配置项mysql-conf。

    key:my.cnf。

    value:

[client]
default-character-set=utf8mb4
 
[mysql]
default-character-set=utf8mb4
 
[mysqld]
init_connect='SET collation_connection = utf8mb4_unicode_ci'
init_connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
skip-character-set-client-handshake
skip-name-resolve

2) 存储管理-创建存储卷mysql-pvc。

    存储类型:nfs-storage。

3) 应用负载-创建有状态副本集xx-mysql。

    镜像:mysql:5.7.35,使用默认端口。

    环境变量:MYSQL_ROOT_PASSWORD=root。

    同步主机时区。

    存储卷:mysql-pvc,读写,/var/lib/mysql。

    配置文件:mysql-conf,只读,/etc/mysql/conf.d。

【参考】部署MySQL负载均衡网络。

1) 应用负载-删除默认创建的服务xx-mysql-xxxx。(可以跳过)

2) 应用负载-创建服务-指定工作负载-创建服务xx-mysql。

    访问类型:通过集群内部IP来访问服务Virtual IP。

    指定工作负载:有状态副本集xx-mysql。

    端口:TCP,tcp-3306,3306,3306。

    外网访问:NodePort。

3) 创建服务xx-mysql后得到一个外网访问的端口号。

    通过 IP地址+端口号 可以访问MySQL服务。

【参考】部署Redis。

1) 配置中心-创建配置项redis-conf。

    key:redis.conf。

    value:

appendonly yes
port 6379
bind 0.0.0.0

2) 应用负载-创建有状态副本集xx-redis。

    镜像:redis,使用默认端口。

    启动命令:redis-server,参数:/etc/redis/redis.conf。

    同步主机时区。

    添加存储卷:redis-pvc,存储类型:nfs-storage,读写,/data。

    配置文件:redis-conf,只读,/etc/redis。

【参考】部署Redis负载均衡网络。

1) 应用负载-删除默认创建的服务xx-redis-xxxx。(可以跳过)

2) 应用负载-创建服务-指定工作负载-创建服务xx-redis。

    访问类型:通过集群内部IP来访问服务Virtual IP。

    指定工作负载:有状态副本集xx-redis。

    端口:TCP,tcp-6379,6379,6379。

    外网访问:NodePort。

3) 创建服务xx-redis后得到一个外网访问的端口号。

    通过 IP地址+端口号 可以访问Redis服务。

【参考】部署Elasticsearch。

1) 配置中心-创建配置项es-conf。

    key1:elasticsearch.yml。

    value1:

cluster.name:"docker-cluster"
network.host:0.0.0.0

    key2:jvm.options。

    value2:比较长,从Linux本地复制一下。

2) 应用负载-创建有状态副本集xx-es。

   镜像:elasticsearch:7.13.4,使用默认端口。

    环境变量:discovery.type=single-node,ES_JAVA_OPTS=-Xms512m -Xmx512m。

    同步主机时区。

    添加存储卷:es-pvc,存储类型:nfs-storage,读写,/usr/share/elasticsearch/data。

    配置文件:es-conf,只读,/usr/share/elasticsearch/config/elasticsearch.yml,子路径elasticsearch.yml,特定键和路径elasticsearch.yml和elasticsearch.yml。

    配置文件:es-conf,只读,/usr/share/elasticsearch/config/jvm.options,子路径jvm.options,特定键和路径jvm.options和jvm.options。

【参考】部署Elasticsearch负载均衡网络。

1) 应用负载-删除默认创建的服务xx-es-xxxx。(可以跳过)

2) 应用负载-创建服务-指定工作负载-创建服务xx-es。

    访问类型:通过集群内部IP来访问服务Virtual IP。

    指定工作负载:有状态副本集xx-es。

    端口:TCP,tcp-9200,9200,9200,TCP,tcp-9300,9300,9300。

    外网访问:NodePort。

3) 创建服务xx-es后得到一个外网访问的端口号。

    通过 IP地址+端口号 可以访问Elasticsearch服务。

【参考】通过应用商店部署RabbitMQ。

1) 应用商店-RabbitMQ-部署。

    应用名称、版本。

    企业空间-集群-项目。

    enable Data Persistence。

    username、passwork。

2) 编辑外网访问。

    访问方式:NodePort。

    通过 IP地址+端口号 可以访问RabbitMQ服务。

KubeSphere部署项目

【推荐】项目上云的四个要点。

1) 部署中间件。

    以有状态副本集方式部署、导入默认数据。

2) 部署微服务。

    制作镜像、无状态部署。

3) 搭建网络。

    中间件、微服务之间一般通过内网互相访问。

4) 配置。

    生产配置分离。

【参考】项目上云。

1) 部署MySQL、Redis。

2) 迁移数据库。

    MySQL Workbench提供了快捷方式。

    按照向导一步一步进行迁移。

3) 部署Nacos。

    配置中心-创建配置nacos-conf。

        key1:application.properties。

        value2:比较长,从本地复制一下。

            修改:# Connect URL of DB,127.0.0.1:3306 => xx-mysql.xx:3306,修改用户名、密码。

        key2:cluster.conf。

        value2:比较长,从本地复制一下。

            添加:

                xx-nacos-v1-0.xx-nacos.xx.svc.cluster.local:8848

    应用负载-创建有状态服务xx-nacos。

        1副本。

        镜像:nacos/nacos-server:v2.0.3。

        服务设置:TCP,tcp-8848,8848,8848。

        健康检查器:存活检查,HTTP,/nacos,8848。

        环境变量:MODE,standalone。

        同步主机时区。

        配置文件:nacos-conf,只读,/home/nacos/conf/application.properties,子路径application.properties,特定键和路径application.properties和application.properties。

        配置文件:nacos-conf,只读,/home/nacos/conf/cluster.conf,子路径cluster.conf,特定键和路径cluster.conf和cluster.conf。

4) 部署微服务。

    将微服务打包成镜像。

        使用Maven打包微服务。

        在微服务中创建Dockerfile。

        (示例Dockerfile中读取的是prod环境的配置,需事先在Nacos配置中心创建prod配置文件)

FROM openjdk:8-jdk
LABEL maintainer=lalixiaozhu

# docker run -e PARAMS="--server.port 9090"
ENV PARAMS="--server.port=8080 --spring.profiles.active=prod --spring.cloud.nacos.discovery.server-addr=xx-nacos.xx:8848 --spring.cloud.nacos.config.server-addr=xx-nacos.xx:8848 --spring.cloud.nacos.config.namespace=prod --spring.cloud.nacos.config.file-extension=yml"
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone

COPY target/*.jar /app.jar
EXPOSE 8080

ENTRYPOINT ["/bin/sh","-c","java -Dfile.encoding=utf8 -Djava.security.egd=file:/dev/./urandom -jar app.jar ${PARAMS}"]

        创建一个文件夹,名称为服务名,放入Dockerfile,并创建target/,放入jar包。

        将服务文件夹上传到任一服务器节点。

        在服务器上执行:

docker build -t xx-xx:v1.0 -f Dockerfile .

    开通阿里云-容器镜像服务。

        创建公开的命名空间。

        查看命名空间详情,看到操作指南。

        根据操作指南,将镜像推送到Registry。

    应用负载-创建无状态服务。

        微服务名,版本号。

        镜像:已推送镜像,使用默认端口。

        同步主机时区。

    配置微服务。

        在Nacos配置中心修改微服务的线上配置,确保微服务使用的是我们部署在服务器上的中间件。

    按以上流程部署所有微服务。

5 DevOps

【强制】DevOps。

DevOps,开发运维一体化,是一组过程、方法与系统的统称,用于促进开发、技术运营和质量保证部门之间的沟通、协作与整合。

随着敏捷软件开发日趋流行,持续集成(CI)和持续交付(CD)已经成为该领域一个理想的解决方案。在CI/CD工作流中,每次集成都通过自动化构建来验证,包括编码、发布和测试,从而帮助开发者提前发现集成错误,团队也可以快速、安全、可靠地将内部软件交付到生产环境。

【参考】创建DevOps工程。

1) 使用企业self-provisioner账号登录,创建一个DevOps工程。

    邀请其他用户加入工程,可选身份:工程管理员、工程普通成员、工程观察者。

2) 使用工程管理员账号登录,创建流水线。

3) 编辑流水线,选择持续集成&交付(CI/CD)模板。

    拉取代码。

        指定容器maven。

            git。

                添加凭证。选择分支。

    项目编译。

        指定容器maven。

            shell脚本。

mvn clean package -Dmaven.test.skip=true

    构建镜像。

        在微服务target目录下准备好Dockerfile和jar包。

        指定容器maven。

            shell脚本。

docker build -t <微服务名>:latest -f <微服务名>/Dockerfile ./<微服务名>/

        并行构建其他所有微服务镜像。

    推送镜像。

        指定容器maven。

            shell脚本。

docker tag <微服务名>:latest $REGISTRY/$DOCKERHUB_NAMESPACE/<微服务名>:SNAPSHOT-$BUILD_NUMBE

docker push $REGISTRY/$DOCKERHUB_NAMESPACE/<微服务名>:SNAPSHOT-$BUILD_NUMBE

           添加凭证。

   部署到dev环境。

       配置 <微服务名>/deploy/**

       启用变量替换 true

       kubeconfigId "$KUBECONFIG_CREDENTIAL_ID"

   发送确认邮件。

       邮件。

4) 排错、排错、还是排错。

5) 创建另一个流水线,用来部署前端代码。

   拉取代码。

   项目编译。

   构建镜像。

   推送到dev环境。

   发送确认邮件。

6) 在Gitee上为仓库添加WebHook。

   当检测到分支代码发生变化时,触发流水线运行。

6 附录

6.1 Kubernetes附录

sc.yaml

## 创建了一个存储类
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nfs-storage
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: k8s-sigs.io/nfs-subdir-external-provisioner
parameters:
  archiveOnDelete: "true"  ## 删除pv的时候,pv的内容是否要备份

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-client-provisioner
  labels:
    app: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: default
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: nfs-client-provisioner
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccountName: nfs-client-provisioner
      containers:
        - name: nfs-client-provisioner
          image: registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/nfs-subdir-external-provisioner:v4.0.2
          # resources:
          #    limits:
          #      cpu: 10m
          #    requests:
          #      cpu: 10m
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: k8s-sigs.io/nfs-subdir-external-provisioner
            - name: NFS_SERVER
              value: 172.31.0.4 ## 指定自己nfs服务器地址
            - name: NFS_PATH  
              value: /nfs/data  ## nfs服务器共享的目录
      volumes:
        - name: nfs-client-root
          nfs:
            server: 172.31.0.4
            path: /nfs/data
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-provisioner-runner
rules:
  - apiGroups: [""]
    resources: ["nodes"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["persistentvolumes"]
    verbs: ["get", "list", "watch", "create", "delete"]
  - apiGroups: [""]
    resources: ["persistentvolumeclaims"]
    verbs: ["get", "list", "watch", "update"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["storageclasses"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-nfs-client-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: default
roleRef:
  kind: ClusterRole
  name: nfs-client-provisioner-runner
  apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: default
rules:
  - apiGroups: [""]
    resources: ["endpoints"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: default
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: default
roleRef:
  kind: Role
  name: leader-locking-nfs-client-provisioner
  apiGroup: rbac.authorization.k8s.io

6.2 KubeSphere附录

metrics.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels:
    k8s-app: metrics-server
    rbac.authorization.k8s.io/aggregate-to-admin: "true"
    rbac.authorization.k8s.io/aggregate-to-edit: "true"
    rbac.authorization.k8s.io/aggregate-to-view: "true"
  name: system:aggregated-metrics-reader
rules:
- apiGroups:
  - metrics.k8s.io
  resources:
  - pods
  - nodes
  verbs:
  - get
  - list
  - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels:
    k8s-app: metrics-server
  name: system:metrics-server
rules:
- apiGroups:
  - ""
  resources:
  - pods
  - nodes
  - nodes/stats
  - namespaces
  - configmaps
  verbs:
  - get
  - list
  - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server-auth-reader
  namespace: kube-system
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: extension-apiserver-authentication-reader
subjects:
- kind: ServiceAccount
  name: metrics-server
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server:system:auth-delegator
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:auth-delegator
subjects:
- kind: ServiceAccount
  name: metrics-server
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  labels:
    k8s-app: metrics-server
  name: system:metrics-server
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:metrics-server
subjects:
- kind: ServiceAccount
  name: metrics-server
  namespace: kube-system
---
apiVersion: v1
kind: Service
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server
  namespace: kube-system
spec:
  ports:
  - name: https
    port: 443
    protocol: TCP
    targetPort: https
  selector:
    k8s-app: metrics-server
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server
  namespace: kube-system
spec:
  selector:
    matchLabels:
      k8s-app: metrics-server
  strategy:
    rollingUpdate:
      maxUnavailable: 0
  template:
    metadata:
      labels:
        k8s-app: metrics-server
    spec:
      containers:
      - args:
        - --cert-dir=/tmp
        - --kubelet-insecure-tls
        - --secure-port=4443
        - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
        - --kubelet-use-node-status-port
        image: registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/metrics-server:v0.4.3
        imagePullPolicy: IfNotPresent
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /livez
            port: https
            scheme: HTTPS
          periodSeconds: 10
        name: metrics-server
        ports:
        - containerPort: 4443
          name: https
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /readyz
            port: https
            scheme: HTTPS
          periodSeconds: 10
        securityContext:
          readOnlyRootFilesystem: true
          runAsNonRoot: true
          runAsUser: 1000
        volumeMounts:
        - mountPath: /tmp
          name: tmp-dir
      nodeSelector:
        kubernetes.io/os: linux
      priorityClassName: system-cluster-critical
      serviceAccountName: metrics-server
      volumes:
      - emptyDir: {}
        name: tmp-dir
---
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
  labels:
    k8s-app: metrics-server
  name: v1beta1.metrics.k8s.io
spec:
  group: metrics.k8s.io
  groupPriorityMinimum: 100
  insecureSkipTLSVerify: true
  service:
    name: metrics-server
    namespace: kube-system
  version: v1beta1
  versionPriority: 100

kubesphere-installer.yaml

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: clusterconfigurations.installer.kubesphere.io
spec:
  group: installer.kubesphere.io
  versions:
  - name: v1alpha1
    served: true
    storage: true
  scope: Namespaced
  names:
    plural: clusterconfigurations
    singular: clusterconfiguration
    kind: ClusterConfiguration
    shortNames:
    - cc

---
apiVersion: v1
kind: Namespace
metadata:
  name: kubesphere-system

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: ks-installer
  namespace: kubesphere-system

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: ks-installer
rules:
- apiGroups:
  - ""
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - apps
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - extensions
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - batch
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - rbac.authorization.k8s.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - apiregistration.k8s.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - apiextensions.k8s.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - tenant.kubesphere.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - certificates.k8s.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - devops.kubesphere.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - monitoring.coreos.com
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - logging.kubesphere.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - jaegertracing.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - storage.k8s.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - admissionregistration.k8s.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - policy
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - autoscaling
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - networking.istio.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - config.istio.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - iam.kubesphere.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - notification.kubesphere.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - auditing.kubesphere.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - events.kubesphere.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - core.kubefed.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - installer.kubesphere.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - storage.kubesphere.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - security.istio.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - monitoring.kiali.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - kiali.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - networking.k8s.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - kubeedge.kubesphere.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - types.kubefed.io
  resources:
  - '*'
  verbs:
  - '*'

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: ks-installer
subjects:
- kind: ServiceAccount
  name: ks-installer
  namespace: kubesphere-system
roleRef:
  kind: ClusterRole
  name: ks-installer
  apiGroup: rbac.authorization.k8s.io

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ks-installer
  namespace: kubesphere-system
  labels:
    app: ks-install
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ks-install
  template:
    metadata:
      labels:
        app: ks-install
    spec:
      serviceAccountName: ks-installer
      containers:
      - name: installer
        image: kubesphere/ks-installer:v3.1.1
        imagePullPolicy: "Always"
        resources:
          limits:
            cpu: "1"
            memory: 1Gi
          requests:
            cpu: 20m
            memory: 100Mi
        volumeMounts:
        - mountPath: /etc/localtime
          name: host-time
      volumes:
      - hostPath:
          path: /etc/localtime
          type: ""
        name: host-time

cluster-configuration.yaml

---
apiVersion: installer.kubesphere.io/v1alpha1
kind: ClusterConfiguration
metadata:
  name: ks-installer
  namespace: kubesphere-system
  labels:
    version: v3.1.1
spec:
  persistence:
    storageClass: ""        # If there is no default StorageClass in your cluster, you need to specify an existing StorageClass here.
  authentication:
    jwtSecret: ""           # Keep the jwtSecret consistent with the Host Cluster. Retrieve the jwtSecret by executing "kubectl -n kubesphere-system get cm kubesphere-config -o yaml | grep -v "apiVersion" | grep jwtSecret" on the Host Cluster.
  local_registry: ""        # Add your private registry address if it is needed.
  etcd:
    monitoring: true       # Enable or disable etcd monitoring dashboard installation. You have to create a Secret for etcd before you enable it.
    endpointIps: 172.31.0.4  # etcd cluster EndpointIps. It can be a bunch of IPs here.
    port: 2379              # etcd port.
    tlsEnable: true
  common:
    redis:
      enabled: true
    openldap:
      enabled: true
    minioVolumeSize: 20Gi # Minio PVC size.
    openldapVolumeSize: 2Gi   # openldap PVC size.
    redisVolumSize: 2Gi # Redis PVC size.
    monitoring:
      # type: external   # Whether to specify the external prometheus stack, and need to modify the endpoint at the next line.
      endpoint: http://prometheus-operated.kubesphere-monitoring-system.svc:9090 # Prometheus endpoint to get metrics data.
    es:   # Storage backend for logging, events and auditing.
      # elasticsearchMasterReplicas: 1   # The total number of master nodes. Even numbers are not allowed.
      # elasticsearchDataReplicas: 1     # The total number of data nodes.
      elasticsearchMasterVolumeSize: 4Gi   # The volume size of Elasticsearch master nodes.
      elasticsearchDataVolumeSize: 20Gi    # The volume size of Elasticsearch data nodes.
      logMaxAge: 7                     # Log retention time in built-in Elasticsearch. It is 7 days by default.
      elkPrefix: logstash              # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log.
      basicAuth:
        enabled: false
        username: ""
        password: ""
      externalElasticsearchUrl: ""
      externalElasticsearchPort: ""
  console:
    enableMultiLogin: true  # Enable or disable simultaneous logins. It allows different users to log in with the same account at the same time.
    port: 30880
  alerting:                # (CPU: 0.1 Core, Memory: 100 MiB) It enables users to customize alerting policies to send messages to receivers in time with different time intervals and alerting levels to choose from.
    enabled: true         # Enable or disable the KubeSphere Alerting System.
    # thanosruler:
    #   replicas: 1
    #   resources: {}
  auditing:                # Provide a security-relevant chronological set of records,recording the sequence of activities happening on the platform, initiated by different tenants.
    enabled: true         # Enable or disable the KubeSphere Auditing Log System. 
  devops:                  # (CPU: 0.47 Core, Memory: 8.6 G) Provide an out-of-the-box CI/CD system based on Jenkins, and automated workflow tools including Source-to-Image & Binary-to-Image.
    enabled: true             # Enable or disable the KubeSphere DevOps System.
    jenkinsMemoryLim: 2Gi      # Jenkins memory limit.
    jenkinsMemoryReq: 1500Mi   # Jenkins memory request.
    jenkinsVolumeSize: 8Gi     # Jenkins volume size.
    jenkinsJavaOpts_Xms: 512m  # The following three fields are JVM parameters.
    jenkinsJavaOpts_Xmx: 512m
    jenkinsJavaOpts_MaxRAM: 2g
  events:                  # Provide a graphical web console for Kubernetes Events exporting, filtering and alerting in multi-tenant Kubernetes clusters.
    enabled: true         # Enable or disable the KubeSphere Events System.
    ruler:
      enabled: true
      replicas: 2
  logging:                 # (CPU: 57 m, Memory: 2.76 G) Flexible logging functions are provided for log query, collection and management in a unified console. Additional log collectors can be added, such as Elasticsearch, Kafka and Fluentd.
    enabled: true         # Enable or disable the KubeSphere Logging System.
    logsidecar:
      enabled: true
      replicas: 2
  metrics_server:                    # (CPU: 56 m, Memory: 44.35 MiB) It enables HPA (Horizontal Pod Autoscaler).
    enabled: false                   # Enable or disable metrics-server.
  monitoring:
    storageClass: ""                 # If there is an independent StorageClass you need for Prometheus, you can specify it here. The default StorageClass is used by default.
    # prometheusReplicas: 1          # Prometheus replicas are responsible for monitoring different segments of data source and providing high availability.
    prometheusMemoryRequest: 400Mi   # Prometheus request memory.
    prometheusVolumeSize: 20Gi       # Prometheus PVC size.
    # alertmanagerReplicas: 1          # AlertManager Replicas.
  multicluster:
    clusterRole: none  # host | member | none  # You can install a solo cluster, or specify it as the Host or Member Cluster.
  network:
    networkpolicy: # Network policies allow network isolation within the same cluster, which means firewalls can be set up between certain instances (Pods).
      # Make sure that the CNI network plugin used by the cluster supports NetworkPolicy. There are a number of CNI network plugins that support NetworkPolicy, including Calico, Cilium, Kube-router, Romana and Weave Net.
      enabled: true # Enable or disable network policies.
    ippool: # Use Pod IP Pools to manage the Pod network address space. Pods to be created can be assigned IP addresses from a Pod IP Pool.
      type: calico # Specify "calico" for this field if Calico is used as your CNI plugin. "none" means that Pod IP Pools are disabled.
    topology: # Use Service Topology to view Service-to-Service communication based on Weave Scope.
      type: none # Specify "weave-scope" for this field to enable Service Topology. "none" means that Service Topology is disabled.
  openpitrix: # An App Store that is accessible to all platform tenants. You can use it to manage apps across their entire lifecycle.
    store:
      enabled: true # Enable or disable the KubeSphere App Store.
  servicemesh:         # (0.3 Core, 300 MiB) Provide fine-grained traffic management, observability and tracing, and visualized traffic topology.
    enabled: true     # Base component (pilot). Enable or disable KubeSphere Service Mesh (Istio-based).
  kubeedge:          # Add edge nodes to your cluster and deploy workloads on edge nodes.
    enabled: true   # Enable or disable KubeEdge.
    cloudCore:
      nodeSelector: {"node-role.kubernetes.io/worker": ""}
      tolerations: []
      cloudhubPort: "10000"
      cloudhubQuicPort: "10001"
      cloudhubHttpsPort: "10002"
      cloudstreamPort: "10003"
      tunnelPort: "10004"
      cloudHub:
        advertiseAddress: # At least a public IP address or an IP address which can be accessed by edge nodes must be provided.
          - ""            # Note that once KubeEdge is enabled, CloudCore will malfunction if the address is not provided.
        nodeLimit: "100"
      service:
        cloudhubNodePort: "30000"
        cloudhubQuicNodePort: "30001"
        cloudhubHttpsNodePort: "30002"
        cloudstreamNodePort: "30003"
        tunnelNodePort: "30004"
    edgeWatcher:
      nodeSelector: {"node-role.kubernetes.io/worker": ""}
      tolerations: []
      edgeWatcherAgent:
        nodeSelector: {"node-role.kubernetes.io/worker": ""}
        tolerations: []
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值