作者:方忠,蘇州威視通智能科技有限公司技術經理,開源技術愛好者,長期活躍於 dromara 開源社區並參與貢獻。
公司介紹
公司簡介
蘇州威視通智能科技有限公司,是一家全球領先的全景 AI 平臺提供商,結合極致高效的數字孿生技術,實現房建公建、地產物業、城市更新、應急管理、石油化工、家裝、零售等多元行業數字化賦能。
公司平臺介紹
公司技術現狀
- 框架:SpringCloud
- 部署模式:手動 Docker Compose
- 監控:無
- 告警:無
- 日誌查看:手動 Docker logs
- 服務運維:純手動
背景介紹
業務規模增長和痛點
隨着公司業務增長,雲端服務器和邊端服務器數量增長迅速,而且伴隨着海外業務的落地海外服務器也迅速增長,如果使用現在的技術去做運維,肯定是不可取的。
雲原生的優勢
雲原生具有以下優勢(篇幅所限,不展開介紹):
- 彈性擴展
- 高可用
- 高效運維
- 快速迭代
- 降低成本
- 靈活部署
- 簡化架構設計
- 提高可移植性
選型說明
我們最終選擇了 KubeSphere,是因爲其具有以下功能特性,較符合我們的需求:
- 簡單多樣化的安裝方式(All in one、K8s、AWS)
- 集羣可視化、監控可視化
- 多集羣管理、多租戶管理
- 一體化的 DevOps(Jenkins+GitOps)
- 豐富的開源組件(Fluent Bit、tower、jaeger)
- 開箱即用的微服務治理
- 支持 KubeEdge 邊端運維
實踐過程
架構演變
技術架構
生產集羣規模
目前我們國內的業務部署在華爲雲、日本的業務部署在 AWS 上。
KubeSphere 安裝
- 安裝方式有 All-in-one、多節點和離線等多種安裝方式,我們使用的是多節點安裝
- 需要預先安裝 socat、conntrack、ebtables、ipset
- 創建配置文件
// 版本號可以按照自己的需求配置
./kk create config --with-kubernetes v1.22.12 --with-kubesphere v3.3.0
// 使用修改後的配置文件安裝集羣
./kk create cluster -f config-sample.yaml
- 安裝完成後控制檯可以顯示所有節點信息
多集羣配置
- 多集羣的連接方式有直接連接和代理連接,目前我的環境兩套集羣網絡不互通所以採用了代理連接的方式
// 主集羣配置
kubectl edit cc ks-installer -n kubesphere-system
// 配置文件修改
multicluster:
clusterRole: host
hostClusterName: <主集羣名稱>
// 獲取主集羣的jwtSecret
kubectl -n kubesphere-system get cm kubesphere-config -o yaml | grep -v "apiVersion" | grep jwtSecret
// 配置成員集羣
kubectl edit cc ks-installer -n kubesphere-system
// 成員集羣配置文件修改
authentication:
jwtSecret: gfIwilcc0WjNGKJ5DLeksf2JKfcLgTZU
multicluster:
clusterRole: member
- 在主集羣上登錄 KubeSphere 控制檯添加集羣即可
服務部署
- 製作服務的 dockerfile,以 gateway 服務爲例
// 以springcloud的gateway服務爲例
FROM swr.cn-east.myhuaweicloud.com/vsais/openjdk:11.0.02
MAINTAINER xxx
WORKDIR /home
COPY vs-gateway/target/vs-gateway.jar /home/vs-gateway.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","vs-gateway.jar"]
- 製作 gateway 的 service 文件
kind: Service
apiVersion: v1
metadata:
name: gateway
namespace: test
labels:
app: gateway
version: v1
annotations:
kubesphere.io/creator: admin
kubesphere.io/serviceType: statelessservice
spec:
ports:
- name: http-0
protocol: TCP
port: 8080
targetPort: 8080
selector:
app: gateway
type: ClusterIP
- 部署 service 服務
- 製作 gateway 的 deployment 文件並部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: gateway # Deployment 對象的名稱,與應用名稱保持一致
namespace: test
labels:
app: gateway # 應用名稱
spec:
selector:
matchLabels:
app: gateway #app 標籤名稱
replicas: 1
minReadySeconds: 30
strategy: #部署策略更多策略 1.https://www.qikqiak.com/post/k8s-deployment-strategies/
type: RollingUpdate #其他類型如下 1.重建(Recreate) 開發環境使用 2.RollingUpdate(滾動更新)
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
template:
metadata:
labels:
app: gateway
spec:
volumes:
- name: timezone-volume
configMap:
name: timezone-config
items:
- key: localtime
path: localtime
restartPolicy: Always
containers:
- name: gateway # 容器名稱,與應用名稱保持一致
image: swr.cn-east.myhuaweicloud.com/vsais/gateway-test:v2.19
env:
- name: TZ
value: "Asia/Shanghai"
volumeMounts:
- name: timezone-volume
readOnly: true
mountPath: /etc/localtime
subPath: localtime
imagePullPolicy: Always #鏡像拉取策略 1.IfNotPresent如果本地存在鏡像就優先使用本地鏡像。2.Never直接不再去拉取鏡像了,使用本地的.如果本地不存在就報異常了。
ports:
- containerPort: 8080 #應用監聽的端口
protocol: TCP #協議 tcp和 udp
livenessProbe:
httpGet:
path: /actuator/health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
failureThreshold: 10
readinessProbe:
httpGet:
path: /actuator/health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
failureThreshold: 10
imagePullSecrets:
- name: huawei
- gateway 服務依賴了 configmap 和 secret 配置
// configmap
apiVersion: v1
kind: ConfigMap
metadata:
name: timezone-config
data:
localtime: /usr/share/zoneinfo/Asia/Shanghai
// secret
kind: Secret
apiVersion: v1
metadata:
name: dockerhub
namespace: test
annotations:
kubesphere.io/creator: admin
secret.kubesphere.io/force-insecure: 'true'
data:
.dockerconfigjson: >-
eyJhdXRocyI6eyY2tlci5pbyIXxVlcCIsInBhc3N3b3JkIjoiVlNBSVNfdnNkZWVwMjAyMCIsImVtYWlsIjoiIiwiYXV0aCI3T2VFFVbFRYM1p6Wkd9In19fQ==
type: kubernetes.io/dockerconfigjson
- 其他服務依賴了 pvc 配置
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: report
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
- 服務代碼配置
// 直接使用nacos的服務名來通信
<profile>
<id>prod</id>
<properties>
<profiles.active>prod</profiles.active>
<nacos.server>nacos.prod:8848</nacos.server>
<nacos.discovery.group>PROD_GROUP</nacos.discovery.group>
<nacos.config.group>PROD_GROUP</nacos.config.group>
<logstash.address>127.0.0.1:4560</logstash.address>
</properties>
</profile>
監控
CI/CD
CI 這塊我們使用了其他開源項目,CD 則使用了 Argo CD 同步服務。
未來規劃
- 鑑於 KubeSphere 在華爲雲和 AWS-日本的成功落地、年底繼續着手在 AWS-新加坡的部署
- 使用 EdgeMesh,徹底打通雲邊、邊邊的網絡通信
- 使用灰度發佈代替滾動更新部署
- 使用 CPU 技術虛擬化 CPU,KubeSphere 是否有此功能待探究
本文由博客一文多發平臺 OpenWrite 發佈!