您的位置:首页 > 其它

k8s安装jenkins

2020-10-16 18:14 483 查看


创建自己的空间

cat 01-jenkins-ns.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: jenkins-k8s

cat 02-jenkins-pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: jenkins-k8s-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
  - ReadWriteMany
  nfs:
    server: 172.16.10.222
    path: /data/jenkins

cat 03-jenkins-pvc.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-k8s-pvc
  namespace: jenkins-k8s
spec:
  resources:
    requests:
      storage: 10Gi
  accessModes:
    - ReadWriteMany

cat 04-jenkins-account.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: jenkins-k8s-sa
  namespace: jenkins-k8s

cat 05-jenkins-cluster-role-binding.yaml

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: jenkins-k8s-sa-cluster
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: jenkins-k8s-sa
  namespace: jenkins-k8s

cat 06-jenkins-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins
  namespace: jenkins-k8s
spec:
  replicas: 1
  selecto
1c7c
r:
    matchLabels:
      app: jenkins
  template:
    metadata:
      labels:
        app: jenkins
    spec:
      serviceAccount: jenkins-k8s-sa
      containers:
      - name: jenkins
        image: jenkins/jenkins:lts
        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: 512Mi
        livenessProbe:
          httpGet:
            path: /login
            port: 8080
          initialDelaySeconds: 60
          timeoutSeconds: 5
          failureThreshold: 12
        readinessProbe:
          httpGet:
            path: /login
            port: 8080
          initialDelaySeconds: 60
          timeoutSeconds: 5
          failureThreshold: 12
        volumeMounts:
        - name: jenkins-volume
          subPath: jenkins-home
          mountPath: /var/jenkins_home
      volumes:
      - name: jenkins-volume
        persistentVolumeClaim:
          claimName: jenkins-k8s-pvc

cat 07-jenkins-service.yaml

apiVersion: v1 
kind: Service
metadata:
  name: jenkins-service
  namespace: jenkins-k8s
  labels:
    app: jenkins 
spec: 
  selector: 
    app: jenkins 
  type: NodePort 
  ports: 
  - name: web 
    port: 8080 
    targetPort: web 
    nodePort: 30012 
  - name: agent 
    port: 50000 
    targetPort: agent


密码在自己映射的路径下,我自己nfs的路径是

/data/jenkins/jenkins-home/secrets

cat initialAdminPassword
85b3fe48c3884993b7147a4977ab113a

点击推荐就行

创建用户

下一步

保存并完成

开始使用

然后就可以配置了

安装k8s插件

Manage Jnekins------>插件管理------>可选插件------>搜索kubernetes------>
出现如下

下一步,需要搜索才会显示

直接安装

安装完勾中安装完击重启,然后用创建好的密码登录


配置jenkins对接k8s

配置完连接测试

配置pods模板


docker镜像:cnych/jenkins.jnlp

工作目录:/home/jenkins

保存就行,然后就可以写pipline构建自己的代码了。




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: