Kubernetes SpringCloud持续集成 - 安装jenkins、配置模板pod(一)
程序员文章站
2022-08-29 14:08:19
1 k8s环境概述192.168.38.50 master192.168.38.51 node1192.168.38.52 node2192.168.38.100 harbor/nfs2 PV/PVC#创建命名空间kubectl create namespace jenkins-k8s2.1 创建PVvim jenkins-pv.yaml apiVersion: v1kind: PersistentVolumemetadata: name: jenkins-p...
1 k8s环境概述
192.168.38.50 master
192.168.38.51 node1
192.168.38.52 node2
192.168.38.100 harbor/nfs
2 PV/PVC
#创建命名空间
kubectl create namespace jenkins-k8s
2.1 创建PV
vim jenkins-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: jenkins-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
nfs:
path: /usr/local/kubernetes/volumes/jenkins
server: 192.168.38.100
#应用
kubectl apply -f jenkins-pv.yaml
2.2 创建PVC
vim jenkins-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: jenkins-pvc
namespace: jenkins-k8s
spec:
resources:
requests:
storage: 10Gi
accessModes:
- ReadWriteMany
#应用
kubectl apply -f jenkins-pvc.yaml
3 ServiceAccount
#创建一个sa账号
kubectl create sa jenkins-k8s-sa -n jenkins-k8s
#授权,kubectl create clusterrolebinding 名称、名称空间、绑定clusterrole=cluster-admin
kubectl create clusterrolebinding jenkins-k8s-sa-cluster -n jenkins-k8s --clusterrole=cluster-admin --serviceaccount=jenkins-k8s:jenkins-k8s-sa
4 整合Jenkins
4.1 下载镜像
#node1、node2
docker pull jenkins/jenkins:latest
cnych/jenkins:jnlp6
4.2 jenkins-deployment.yaml
vim jenkins-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
namespace: jenkins-k8s
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
serviceAccountName: jenkins-k8s-sa
containers:
- name: jenkins
image: jenkins/jenkins:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
name: web
protocol: TCP
- containerPort: 50000
name: agent
protocol: TCP
resources:
limits:
cpu: 1000m
memory: 1Gi
requests:
cpu: 500m
memory: 500Mi
livenessProbe:
httpGet:
port: 8080
path: /login
initialDelaySeconds: 60
timeoutSeconds: 5
failureThreshold: 12
readinessProbe:
httpGet:
port: 8080
path: /login
initialDelaySeconds: 60
volumeMounts:
- mountPath: /var/jenkins_home
name: jenkins-volume
subPath: jenkins-home
volumes:
- name: jenkins-volume
persistentVolumeClaim:
claimName: jenkins-pvc
#应用
kubectl apply -f jenkins-deployment.yaml
#查看
kubectl get pod -n jenkins-k8s
#验证
kubectl get pod -o wide -n jenkins-k8s
curl 10.244.2.23:8080
4.3 jenkins-svc.yaml
#创建
vim jenkins-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: jenkins-service
namespace: jenkins-k8s
labels:
app: jenkins
spec:
selector:
app: jenkins
type: ClusterIP
ports:
- port: 8080
name: web
targetPort: web
- name: agent
port: 50000
targetPort: agent
#应用
kubectl apply -f jenkins-svc.yaml
#查看
kubectl get svc -n jenkins-k8s
4.4 jenkins-ingress.yaml
vim jenkins-ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: jenkins
namespace: jenkins-k8s
spec:
rules:
- host: rosh.jenkins.com
http:
paths:
- backend:
serviceName: jenkins-service
servicePort: 8080
#应用
kubectl apply -f jenkins-ingress.yaml
#查看
kubectl get ingress -n jenkins-k8s
5 Jenkins 初始化
5.1 初始化密码
#查看挂载日志,记录初始化密码,填入初始化页面
84f98993d6594792b7e420c74934eb89
5.2 初始化插件
5.3 初始化用户
6 中文插件
7 配置模板pod
Jenkins 的 kubernetes-plugin 在执行构建时会在 kubernetes 集群中自动创建一个 Pod,并在 Pod 内部创建一个名为 jnlp 的容器,该容器会连接 Jenkins 并运行 Agent 程序,形成一个 Jenkins 的 Master 和 Slave 架构,然后 Slave 会执行构建脚本进行构建。
7.1 安装插件
7.2 配置pod模板
7.3 测试
创建pipeline项目:
node('test-rosh') {
stage('拉取代码') {
echo "拉取代码完成"
}
stage('制作镜像,上传harbor'){
echo "制作镜像 完成"
}
stage('代码审查'){
echo "代码审查 完成"
}
stage('远程部署'){
echo "远程部署 完成"
}
}
本文地址:https://blog.csdn.net/qq_34125999/article/details/108744816
上一篇: Glide实现圆角图片,以及圆形图片