使用gitlab完成k8s的CD的上线操作
-
1.创建k8s的编排yaml,放在仓库中
-
2.写CD脚本
-
3.在web界面上进行操作,添加参数
配置参数的地方:
stages:
- deploy
deploy_dev:
when: manual
stage: deploy
only:
- master
- /^feature\/.*$/
- /^feature-.*$/
tags:
- kun
script:
- envsubst < storm.yaml | kubectl apply -f -
variables:
IMAGE: harbor.example.com/default/hello-world-$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA
SERVICE_NAME: hello-world-$CI_COMMIT_REF_SLUG
NAMESPACE: default
NODE_ENV: development
vim storm.yaml
apiVersion: v1
kind: Service
metadata:
name: $SERVICE_NAME
namespace: $NAMESPACE
labels:
app: $SERVICE_NAME
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
selector:
app: $SERVICE_NAME
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: $SERVICE_NAME
namespace: $NAMESPACE
labels:
name: $SERVICE_NAME
spec:
selector:
matchLabels:
name: $SERVICE_NAME
replicas: 1
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
name: $SERVICE_NAME
labels:
name: $SERVICE_NAME
spec:
terminationGracePeriodSeconds: 10
containers:
- name: $SERVICE_NAME
image: $IMAGE
imagePullPolicy: Always
resources:
requests:
memory: "6Gi"
cpu: "3"
limits:
memory: "6Gi"
cpu: "4"
ports:
- containerPort: 8080
name: rpc-port
- containerPort: 7091
name: metr-port
- containerPort: 5000
name: grpc-port
- containerPort: 8719
name: sentinel-port
volumeMounts:
- name: $SERVICE_NAME-log
mountPath: /opt/data1/$SERVICE_NAME/logs/
volumes:
- name: $SERVICE_NAME-log
hostPath:
path: /opt/data1/logs/$SERVICE_NAME/api/prod