星的博客 - gzz2024
type: channel
link: https://axzys.cn/index.php/author/3/
description: gzz2024
items: CICD部署流程

CICD部署流程
type: item
date: 2024-11-18T05:18:00+00:00
description: 第一步：搭建k8s环境，详情见配置文档：https://axzys.cn/admin/manage-posts.php?page=1第二步：在工具集群安装：Jenkins2.1创建jenkins.yaml文件(ps:镜像文件如果下载不下来的话，需要到阿里云部署一个镜像文件，部署文档：xxx)apiVersion: v1 kind: PersistentVolume metadata: name: jenkins-pv labels: type: local spec: capacity: storage: 5Gi accessModes: - "ReadWriteOnce" hostPath: path: /data/jenkins --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: jenkins-pvc spec: accessModes: - "ReadWriteOnce" resources: requests: storage: 5Gi --- apiVersion: apps/v1 kind: Deployment metadata: name: jenkins spec: replicas: 1 selector: matchLabels: app: jenkins template: metadata: labels: app: jenkins spec: containers: - name: jenkins image: registry.cn-hangzhou.aliyuncs.com/vimermaid/jenkins:1.0 ports: - containerPort: 8080 name: web protocol: TCP - containerPort: 50000 name: agent protocol: TCP resources: limits: cpu: 1500m memory: "6Gi" requests: cpu: 1500m memory: "2048Mi" readinessProbe: httpGet: path: /login port: 8080 initialDelaySeconds: 60 timeoutSeconds: 5 failureThreshold: 12 volumeMounts: - name: jenkins-home mountPath: /var/jenkins_home volumes: - name: jenkins-home persistentVolumeClaim: claimName: jenkins-pvc --- apiVersion: v1 kind: Service metadata: name: jenkins-init-service spec: type: NodePort ports: - port: 7096 name: web1 nodePort: 7096 targetPort: 8080 - port: 50000 name: web2 nodePort: 50000 targetPort: 50000 selector: app: jenkins2.2创建本地目录mkdir -p /data/jenkins chmod o+w /data/jenkins2.3扩大端口范围（原因是：kubernetes默认端口号范围是 30000-32767 ，如果期望值不是这个区间则需要更改vi /etc/kubernetes/manifests/kube-apiserver.yaml将文件配置到末端：- --service-node-port-range=1024-65535展示效果 2.3部署jenkins.yaml文件kubectl apply -f jenkins.yaml2.4查看pod：jenkins.yamlkubectl get pods -o wide2.5pod状态变成running后，再查看Jenkins密码kubectl exec -ti jenkins-548bfffcb-mtc4t cat /var/jenkins_home/secrets/initialAdminPassword2.6查看Jenkins的svc：查询暴漏给外部可访问的端口kubectl get svc |grep jenkins2.7登录Jenkins的web页面192.168.1.111:70962.8输入密码，就是上面2.5获取到的密码，并下载推荐插件 2.9为Jenkins制作动态的slave节点 2.9.1安装并配置k8s插件，名字就叫k8s，…