K8S部署jenkins
时间: 2023-11-14 16:07:50 浏览: 135
可以通过以下步骤在Kubernetes上部署Jenkins:
1. 创建一个Jenkins的Docker镜像并将其推送到Docker仓库。
2. 创建一个Kubernetes的Deployment对象,使用上一步中创建的Docker镜像作为容器镜像,并指定所需的环境变量和卷。
3. 创建一个Kubernetes的Service对象,将其暴露在集群内部,以便其他Pod可以访问它。
4. (可选)创建一个Ingress对象,将其暴露在集群外部,以便外部用户可以访问它。
以下是一个示例YAML文件,用于在Kubernetes上部署Jenkins:
```
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: <your-docker-image>
ports:
- containerPort: 8080
name: http
- containerPort: 50000
name: jnlp
env:
- name: JAVA_OPTS
value: "-Djenkins.install.runSetupWizard=false"
- name: JENKINS_OPTS
value: "--prefix=/jenkins"
volumeMounts:
- name: jenkins-home
mountPath: /var/jenkins_home
volumes:
- name: jenkins-home
persistentVolumeClaim:
claimName: jenkins-home
---
apiVersion: v1
kind: Service
metadata:
name: jenkins
spec:
selector:
app: jenkins
ports:
- name: http
port: 8080
targetPort: http
- name: jnlp
port: 50000
targetPort: jnlp
type: ClusterIP
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: jenkins
spec:
rules:
- host: jenkins.example.com
http:
paths:
- path: /jenkins
backend:
serviceName: jenkins
servicePort: http
```
阅读全文