kubernetes中怎么安装Jenkins
发表于:2025-01-23 作者:千家信息网编辑
千家信息网最后更新 2025年01月23日,本篇文章为大家展示了kubernetes中怎么安装Jenkins,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。1、k8s部署Jenkins1)构建Jenkin
千家信息网最后更新 2025年01月23日kubernetes中怎么安装Jenkins
本篇文章为大家展示了kubernetes中怎么安装Jenkins,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
1、k8s部署Jenkins
1)构建Jenkins镜像,使用阿里云的构建镜像Dockerfile如下:
FROM jenkins/jenkins #这个是官方镜像,必须基于官方镜像构建,否则安装之后还是要更新,又报错USER root#清除了基础镜像设置的源,切换成阿里云的jessie源RUN echo '' > /etc/apt/sources.list.d/jessie-backports.list \ && echo "deb http://mirrors.aliyun.com/debian jessie main contrib non-free" > /etc/apt/sources.list \ && echo "deb http://mirrors.aliyun.com/debian jessie-updates main contrib non-free" >> /etc/apt/sources.list \ && echo "deb http://mirrors.aliyun.com/debian-security jessie/updates main contrib non-free" >> /etc/apt/sources.list#更新源并安装缺少的包RUN apt-get update && apt-get install -y libltdl7ARG dockerGid=999RUN echo "docker:x:${dockerGid}:jenkins" >> /etc/group \USER jenkins
2)部署Jenkins镜像
A、创建pv持久化存储卷,本次用的是宿主机文件系统
apiVersion: "v1"kind: "PersistentVolume"metadata: name: jenkins-0spec: capacity: storage: "10Gi" accessModes: - "ReadWriteMany" hostPath : path: /tmp volumeName: jenkins
B、创建账户
kubectl create -f service-account.yml
# In GKE need to get RBAC permissions first with# kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin [--user=|--group= ]---apiVersion: v1kind: ServiceAccountmetadata: name: jenkins namespace: default---kind: RoleapiVersion: rbac.authorization.k8s.io/v1beta1metadata: name: jenkins namespace: defaultrules:- apiGroups: [""] resources: ["pods"] verbs: ["create","delete","get","list","patch","update","watch"]- apiGroups: [""] resources: ["pods/exec"] verbs: ["create","delete","get","list","patch","update","watch"]- apiGroups: [""] resources: ["pods/log"] verbs: ["get","list","watch"]- apiGroups: [""] resources: ["secrets"] verbs: ["get"]---apiVersion: rbac.authorization.k8s.io/v1beta1kind: RoleBindingmetadata: name: jenkinsroleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: jenkinssubjects:- kind: ServiceAccount name: jenkins namespace: default ---kind: ClusterRoleapiVersion: rbac.authorization.k8s.io/v1beta1metadata: name: jenkinsClusterRole namespace: defaultrules:- apiGroups: [""] resources: ["pods"] verbs: ["create","delete","get","list","patch","update","watch"]- apiGroups: [""] resources: ["pods/exec"] verbs: ["create","delete","get","list","patch","update","watch"]- apiGroups: [""] resources: ["pods/log"] verbs: ["get","list","watch"]- apiGroups: [""] resources: ["secrets"] verbs: ["get"]---apiVersion: rbac.authorization.k8s.io/v1beta1kind: RoleBindingmetadata: name: jenkinsClusterRuleBindingroleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: jenkinsClusterRolesubjects:- kind: ServiceAccount name: jenkins namespace: default
C、创建Jenkins服务
kubectl create -f jenkins.yml
# jenkins---apiVersion: apps/v1beta1kind: StatefulSetmetadata: name: jenkins namespace: default labels: name: jenkinsspec: serviceName: jenkins replicas: 1 updateStrategy: type: RollingUpdate template: metadata: name: jenkins labels: name: jenkins spec: terminationGracePeriodSeconds: 10 serviceAccountName: jenkins imagePullSecrets: - name: registry-secret containers: - name: jenkins # image: jenkins/jenkins:lts-alpine # image: chadmoon/jenkins-docker-kubectl:latest h2kkan/jenkins-docker image: registry.cn-shanghai.aliyuncs.com/pml/jenkins:v1.0 imagePullPolicy: Always ports: - containerPort: 8080 - containerPort: 50000 resources: limits: cpu: 1 memory: 1Gi requests: cpu: 0.5 memory: 500Mi env: - name: LIMITS_MEMORY valueFrom: resourceFieldRef: resource: limits.memory divisor: 1Mi - name: JAVA_OPTS # value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1 -XshowSettings:vm -Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 value: -Xmx800m -XshowSettings:vm -Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 volumeMounts: - name: jenkins-home mountPath: /var/jenkins_home - name: docker mountPath: /usr/bin/docker - name: docker-sock mountPath: /var/run/docker.sock securityContext: privileged: true volumes: - name: docker hostPath: path: /usr/bin/docker - name: docker-sock hostPath: path: /var/run/docker.sock volumeClaimTemplates: - metadata: name: jenkins-home # annotations: # volume.beta.kubernetes.io/storage-class: anything spec: accessModes: [ "ReadWriteOnce" ] resources: requests: storage: 1Gi---apiVersion: v1kind: Servicemetadata: name: jenkins namespace: default annotations: # ensure the client ip is propagated to avoid the invalid crumb issue (k8s <1.7) # service.beta.kubernetes.io/external-traffic: OnlyLocalspec: type: NodePort selector: name: jenkins # k8s 1.7+ externalTrafficPolicy: Local ports: - name: http port: 80 targetPort: 8080 protocol: TCP - name: agent port: 50000 protocol: TCP
2、登录并配置Jenkins
1)登录咋说呢,上图吧
找到服务端口
2)浏览器输入node的ip加上端口,诸如:http://192.168.16.131:32453,就可以了
3)装插件,kubernetes plugin
4)配凭据,一个是登录gitee的(下代码),一个是登录docker仓库的(pull/push镜像),还一个是ssh登录k8s的(deploy)
3、找个demo项目吧
看到这了,star/fork一下行不行,看提交记录就知道差点搞疯了!!!
https://gitee.com/chenqq/petclinic/
4、配下流水线
5、enjoy it!!!
如果持久化存储卷声明一直在pending,参考如下,重新设置状态:
{ "kind": "PersistentVolumeClaim", "apiVersion": "v1", "metadata": { "name": "jenkins-home-jenkins-0", "namespace": "default", "selfLink": "/api/v1/namespaces/default/persistentvolumeclaims/jenkins-home-jenkins-0", "uid": "e0e85f5b-b64b-11e9-acc8-000c29e92529", "resourceVersion": "649259", "creationTimestamp": "2019-08-04T00:07:42Z", "labels": { "name": "jenkins" }, "annotations": { "pv.kubernetes.io/bind-completed": "yes", "pv.kubernetes.io/bound-by-controller": "yes" }, "finalizers": [ "kubernetes.io/pvc-protection" ] }, "spec": { "accessModes": [ "ReadWriteOnce" ], "resources": { "requests": { "storage": "1Gi" } }, "volumeName": "jenkins-1", "volumeMode": "Filesystem", "dataSource": null }, "status": { "phase": "Bound", "accessModes": [ "ReadWriteOnce" ], "capacity": { "storage": "10Gi" } }}
上述内容就是kubernetes中怎么安装Jenkins,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。
镜像
登录
内容
官方
技能
知识
端口
存储
更新
服务
不行
简明
简明扼要
仓库
代码
凭据
图吧
基础
宿主
宿主机
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
上海电脑软件开发服务费
数据库的可视化操作
奉贤区企业金融网络技术服务
北理数据库教材
文明重启发现服务器不见了
东营正洁网络技术
百信云龙服务器厂家
20个数据库设计图
最新网络安全政策
论国家网络安全的重要性
数字媒体跟软件开发
2019年网络安全会温州
软件开发合同双方义务
个人软件开发税收优惠
江苏公安局网络安全支队长李晶
为何删除不了数据库
无线网络技术对生活的影响
服务器出现不安全提示
计算机三级网络技术 a类
如何清除数据库的信息
泊众棋牌软件开发公司
论网络安全法法律责任
商场app软件开发
游戏服务器如何设置安全
2020年贵州省网络安全技能
西安系统软件开发
c 直接访问数据库
长沙erp软件开发如何收费
江苏智能软件开发批量定制
吃鸡时如何快速的切换服务器