k8s + gitlab + jenkins +docker 搭建企業級CI/CD 流水線操作
1.gitlab 安裝,管理項目源代碼
1.1 gitlab 安裝,優化
gitlab 優化 2.6G/8G
gitlab
puma =2
1.2 gitlab 管理界面--設置--項目訪問令牌
1.3 webhooks 鈎子
2. jenkins 獲取gitlab 源代碼
2.1 系統配置--插件管理--安裝gitlab --gitlab plugin,gitlab hook plugin,ruby-runtime
2.2 配置 jenkins 憑證提供者:
源碼地址:
doman:全局憑據
類型選擇:gitlab api token
范圍:jenkins,nodes,items,all child items,tec
api token: gitlab 項目訪問令牌
3.harbor 本地鏡像服務器,存放鏡像
4.k8s集群
pod:一個鏡像部署到3個容器,對外服務自動實現負載均衡
demo.yml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: net6-demo-deployment
labels:
app: net6
spec:
# 配置rs
replicas: 3
selector:
matchLabels:
app: net6-rs
## 配置是POD模板
template:
metadata:
labels:
app: net6-rs
env: testing
spec:
containers:
- name: net6-container
imagePullPolicy: Always
image: 192.168.3.251:9999/xxx/dotnet6-piepeline:1221
ports:
- name: net6-port
containerPort: 80 #必須和dockerfile中暴露端口一致
---
apiVersion: v1
kind: Service
metadata:
name: net6-service
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 30335
selector:
app: net6-rs
----------------jenkins----------------
1.拉svn代碼;
2.編譯和生產鏡像
3.推送鏡像docker image 到 本地鏡像倉庫barbor,或推送生產的鏡像到雲鏡像倉庫(鏡像地址);
4.發布:將剛推送的雲鏡像發布到 雲 k8s (需密鑰,鏡像憑證,鏡像地址)