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