一、版本说明
二、部署步骤
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo --no-check-certificate
这里注意,pkg.jenkins.io 的证书过期了,我们要加上--no-check-certificate
[xiaoyu@localhost ~]$ sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo --no-check-certificate
--2022-04-22 19:54:23-- https://pkg.jenkins.io/redhat-stable/jenkins.repo
正在解析主机 pkg.jenkins.io (pkg.jenkins.io)... 151.101.74.133, 2a04:4e42:1a::645
正在连接 pkg.jenkins.io (pkg.jenkins.io)|151.101.74.133|:443... 已连接。
警告: 无法验证 pkg.jenkins.io 的由 “/C=US/O=Let's Encrypt/CN=R3” 颁发的证书:
颁发的证书已经过期。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:85
正在保存至: “/etc/yum.repos.d/jenkins.repo”
100%[=========================================================================================>] 85 --.-K/s 用时 0s
2022-04-22 19:54:24 (6.71 MB/s) - 已保存 “/etc/yum.repos.d/jenkins.repo” [85/85])
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum install fontconfig java-11-openjdk
sudo yum install jenkins
sudo systemctl daemon-reload
上面三条没有什么问题,注意的是给root权限即可。
三、启动
以下命令分别为
- 设置jenkins开机启动
- 启动jenkins服务
- 查看jenkins服务状态
[xiaoyu@localhost ~]$ sudo systemctl enable jenkins
Created symlink from /etc/systemd/system/multi-user.target.wants/jenkins.service to /usr/lib/systemd/system/jenkins.service.
[xiaoyu@localhost ~]$ sudo systemctl start jenkins
[xiaoyu@localhost ~]$ sudo systemctl status jenkins
● jenkins.service - Jenkins Continuous Integration Server
Loaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; vendor preset: disabled)
Active: active (running) since 五 2022-04-22 20:19:45 CST; 10s ago
Main PID: 20521 (java)
Tasks: 42
CGroup: /system.slice/jenkins.service
└─20521 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=%C/jenkins/war --httpPort=8...
4月 22 20:19:28 localhost.localdomain jenkins[20521]: This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword
4月 22 20:19:28 localhost.localdomain jenkins[20521]: *************************************************************
4月 22 20:19:28 localhost.localdomain jenkins[20521]: *************************************************************
4月 22 20:19:28 localhost.localdomain jenkins[20521]: *************************************************************
4月 22 20:19:45 localhost.localdomain jenkins[20521]: 2022-04-22 12:19:45.012+0000 [id=43] INFO h.m.Download...aller
4月 22 20:19:45 localhost.localdomain jenkins[20521]: 2022-04-22 12:19:45.012+0000 [id=43] INFO hudson.util....pt
4月 22 20:19:45 localhost.localdomain jenkins[20521]: 2022-04-22 12:19:45.014+0000 [id=43] INFO hudson.model...23 ms
4月 22 20:19:45 localhost.localdomain jenkins[20521]: 2022-04-22 12:19:45.867+0000 [id=28] INFO jenkins.Init...ation
4月 22 20:19:45 localhost.localdomain jenkins[20521]: 2022-04-22 12:19:45.884+0000 [id=20] INFO hudson.lifec...nning
4月 22 20:19:45 localhost.localdomain systemd[1]: Started Jenkins Continuous Integration Server.
Hint: Some lines were ellipsized, use -l to show in full.
通过增加-l 查看完整信息,我们可以看到jenkins用的是8080端口,初始密码在/var/lib/jenkins/secrets/initialAdminPassword 中,需要root权限查看。
[xiaoyu@localhost ~]$ sudo systemctl status jenkins -l
● jenkins.service - Jenkins Continuous Integration Server
Loaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; vendor preset: disabled)
Active: active (running) since 五 2022-04-22 20:19:45 CST; 2min 44s ago
Main PID: 20521 (java)
Tasks: 35
CGroup: /system.slice/jenkins.service
└─20521 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=%C/jenkins/war --httpPort=8080
4月 22 20:19:28 localhost.localdomain jenkins[20521]: This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword
4月 22 20:19:28 localhost.localdomain jenkins[20521]: *************************************************************
4月 22 20:19:28 localhost.localdomain jenkins[20521]: *************************************************************
4月 22 20:19:28 localhost.localdomain jenkins[20521]: *************************************************************
4月 22 20:19:45 localhost.localdomain jenkins[20521]: 2022-04-22 12:19:45.012+0000 [id=43] INFO h.m.DownloadService$Downloadable
4月 22 20:19:45 localhost.localdomain jenkins[20521]: 2022-04-22 12:19:45.012+0000 [id=43] INFO hudson.util.Retrier
4月 22 20:19:45 localhost.localdomain jenkins[20521]: 2022-04-22 12:19:45.014+0000 [id=43] INFO hudson.model.AsyncPeriodicWork
4月 22 20:19:45 localhost.localdomain jenkins[20521]: 2022-04-22 12:19:45.867+0000 [id=28] INFO jenkins.InitReactorRunner$1
4月 22 20:19:45 localhost.localdomain jenkins[20521]: 2022-04-22 12:19:45.884+0000 [id=20] INFO hudson.lifecycle.Lifecycle
4月 22 20:19:45 localhost.localdomain systemd[1]: Started Jenkins Continuous Integration Server.
[xiaoyu@localhost ~]$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword
9e87859e96cc49b39276d6a63f80df1b
云主机注意需要放行8080端口,不然无法访问。
四、初始配置
浏览器访问服务器的8080端口,即可访问jenkins。
直接选择推荐的插件即可。
创建第一个用户。
下一步是配置地址,建议做一层nginx,生产环境使用域名解析,我这里用的本地虚拟机就这样了。
到此,jenkins安装完成。
五、k8s下的安装
本文采用MacOS下本地安装,基于minikebe。
启动minikube
(base) xiaoyu@localhost ~ % minikube start
😄 Darwin 12.3.1 上的 minikube v1.25.2
? 根据现有的配置文件使用 hyperkit 驱动程序
👍 Starting control plane node minikube in cluster minikube
🏃 Updating the running hyperkit "minikube" VM ...
? This VM is having trouble accessing https://k8s.gcr.io
💡 To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
🐳 正在 Docker 20.10.12 中准备 Kubernetes v1.23.3…
? kubelet.housekeeping-interval=5m
🔎 Verifying Kubernetes components...
? Using image gcr.io/k8s-minikube/storage-provisioner:v5
? Using image kubernetesui/metrics-scraper:v1.0.7
? Using image kubernetesui/dashboard:v2.3.1
🌟 Enabled addons: default-storageclass, storage-provisioner, dashboard
? /usr/local/bin/kubectl is version 1.21.2, which may have incompatibilites with Kubernetes 1.23.3.
? Want kubectl v1.23.3? Try 'minikube kubectl -- get pods -A'
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
创建命名空间
(base) xiaoyu@localhost ~ % kubectl create namespace jenkins
namespace/jenkins created
确定命名空间创建完成。
通过Helm安装jenkins
Helm 是 Kubernetes 的包管理器,可以简化jenkins的安装。
brew install helm
helm repo add jenkinsci https://charts.jenkins.iohelm repo update可以找到jenkinss包(base) xiaoyu@localhost ~ % helm search repo jenkinsciNAME CHART VERSION APP VERSION DESCRIPTION jenkinsci/jenkins 3.12.0 2.332.2 Jenkins - Build great things at any scale!
创建持久卷存储数据
我们采用持久卷的方式挂载数据,防止每次minikube重启的时候丢失数据。
以下内容存放在jenkins-volume.yaml 中,注意,hostPath下path为绝对路径,需要根据实际情况更改。
apiVersion: v1
kind: PersistentVolume
metadata:
name: jenkins-pv
namespace: jenkins
spec:
storageClassName: jenkins-pv
accessModes:
- ReadWriteOnce
capacity:
storage: 20Gi
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /Users/xiaoyu/develop/jenkins-pv/data/
在文件当前目录执行kubectl apply -f jenkins-volume.yaml 。提示已经创建。
(base) xiaoyu@localhost jenkinss-pv % kubectl apply -f jenkins-volume.yamlpersistentvolume/jenkins-pv created
配置权限
(base) xiaoyu@localhost ~ % minikube ssh _ _ _ _ ( ) ( ) ___ ___ (_) ___ (_)| |/') _ _ | |_ __ /' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)$ sudo chown -R 1000:1000 /Users/xiaoyu/develop/jenkinss-pv/data
创建jenkins用户
为了保证安全性,一般我们为某个单独的服务配置单独的管理员用户,用来处理单独的工作。在k8s中,默认配置一个和命名空间一致的用户作为这个命名空间内操作的授权用户。
基于文件即配置的思想,我们依然创建一个文件,名称是jenkins-sa.yaml ,当然名称不是固定的,这样比较好区分。并将下面内容写入文件内,我们可以看到k8s是如何配置用户并分配权限的。
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: jenkins
namespace: jenkins
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
labels:
kubernetes.io/bootstrapping: rbac-defaults
name: jenkins
rules:
- apiGroups:
- '*'
resources:
- statefulsets
- services
- replicationcontrollers
- replicasets
- podtemplates
- podsecuritypolicies
- pods
- pods/log
- pods/exec
- podpreset
- poddisruptionbudget
- persistentvolumes
- persistentvolumeclaims
- jobs
- endpoints
- deployments
- deployments/scale
- daemonsets
- cronjobs
- configmaps
- namespaces
- events
- secrets
verbs:
- create
- get
- watch
- delete
- list
- patch
- update
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- list
- watch
- update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
labels:
kubernetes.io/bootstrapping: rbac-defaults
name: jenkins
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: jenkins
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: Group
name: system:serviceaccounts:jenkins
(base) xiaoyu@localhost jenkinss-pv % kubectl apply -f jenkins-sa.yamlserviceaccount/jenkins createdclusterrole.rbac.authorization.k8s.io/jenkins createdclusterrolebinding.rbac.authorization.k8s.io/jenkins created
以上操作分别完成了创建用户、创建权限、绑定权限操作。
安装 Jenkins
和上面操作一样,新建文件jenkins-values.yaml 。
clusterZone: "cluster.local"
renderHelmLabels: true
controller:
componentName: "jenkins-controller"
image: "jenkins/jenkins"
tagLabel: jdk11
imagePullPolicy: "Always"
imagePullSecretName:
lifecycle:
disableRememberMe: false
numExecutors: 0
executorMode: "NORMAL"
markupFormatter: plainText
customJenkinsLabels: []
adminSecret: true
hostNetworking: false
adminUser: "admin"
admin:
existingSecret: ""
userKey: xiaoyuqingnian
passwordKey: xiaoyuqingnian
jenkinsHome: "/var/jenkins_home"
jenkinsRef: "/usr/share/jenkins/ref"
jenkinsWar: "/usr/share/jenkins/jenkins.war"
resources:
requests:
cpu: "50m"
memory: "256Mi"
limits:
cpu: "2000m"
memory: "4096Mi"
usePodSecurityContext: true
runAsUser: 1000
fsGroup: 1000
securityContextCapabilities: {}
containerSecurityContext:
runAsUser: 1000
runAsGroup: 1000
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
servicePort: 8080
targetPort: 8080
serviceType: ClusterIP
serviceExternalTrafficPolicy:
serviceAnnotations: {}
statefulSetLabels: {}
serviceLabels: {}
podLabels: {}
healthProbes: true
probes:
startupProbe:
httpGet:
path: '{{ default "" .Values.controller.jenkinsUriPrefix }}/login'
port: http
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 12
livenessProbe:
failureThreshold: 5
httpGet:
path: '{{ default "" .Values.controller.jenkinsUriPrefix }}/login'
port: http
periodSeconds: 10
timeoutSeconds: 5
readinessProbe:
failureThreshold: 3
httpGet:
path: '{{ default "" .Values.controller.jenkinsUriPrefix }}/login'
port: http
periodSeconds: 10
timeoutSeconds: 5
podDisruptionBudget:
enabled: false
apiVersion: "policy/v1beta1"
annotations: {}
labels: {}
agentListenerEnabled: true
agentListenerPort: 50000
agentListenerHostPort:
agentListenerNodePort:
agentListenerExternalTrafficPolicy:
agentListenerLoadBalancerSourceRanges:
- 0.0.0.0/0
disabledAgentProtocols:
- JNLP-connect
- JNLP2-connect
csrf:
defaultCrumbIssuer:
enabled: true
proxyCompatability: true
agentListenerServiceType: "ClusterIP"
agentListenerLoadBalancerIP:
agentListenerServiceAnnotations: {}
loadBalancerSourceRanges:
- 0.0.0.0/0
# -Dcom.sun.management.jmxremote.port=4000
# -Dcom.sun.management.jmxremote.authenticate=false
# -Dcom.sun.management.jmxremote.ssl=false
# jmxPort: 4000
# Optionally configure other ports to expose in the controller container
extraPorts: []
# - name: BuildInfoProxy
# port: 9000
installPlugins:
- kubernetes:1.31.3
- workflow-aggregator:2.6
- git:4.10.2
- configuration-as-code:1414.v878271fc496f
installLatestPlugins: true
installLatestSpecifiedPlugins: false
additionalPlugins: []
initializeOnce: false
overwritePluginsFromImage: true
enableRawHtmlMarkupFormatter: false
scriptApproval: []
initScripts: []
# print 'adding global pipeline libraries, register properties, bootstrap jobs...'
additionalExistingSecrets: []
additionalSecrets: []
secretClaims: []
cloudName: "kubernetes"
JCasC:
defaultConfig: true
configScripts: {}
# jenkins:
# systemMessage: Welcome to our CI\CD server. This Jenkins is configured and managed 'as code'.
# Ignored if securityRealm is defined in controller.JCasC.configScripts and
# ignored if controller.enableXmlConfig=true as controller.securityRealm takes precedence
securityRealm: |-
local:
allowsSignup: false
enableCaptcha: false
users:
- id: "${chart-admin-username}"
name: "Jenkins Admin"
password: "${chart-admin-password}"
# Ignored if authorizationStrategy is defined in controller.JCasC.configScripts
authorizationStrategy: |-
loggedInUsersCanDoAnything:
allowAnonymousRead: false
customInitContainers: []
sidecars:
configAutoReload:
enabled: true
image: kiwigrid/k8s-sidecar:1.15.0
imagePullPolicy: IfNotPresent
resources: {}
reqRetryConnect: 10
sshTcpPort: 1044
folder: "/var/jenkins_home/casc_configs"
containerSecurityContext:
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
other: []
schedulerName: ""
nodeSelector: {}
terminationGracePeriodSeconds:
terminationMessagePath:
terminationMessagePolicy:
tolerations: []
affinity: {}
priorityClassName:
podAnnotations: {}
statefulSetAnnotations: {}
updateStrategy: {}
ingress:
enabled: false
paths: []
apiVersion: "extensions/v1beta1"
labels: {}
annotations: {}
hostName:
tls:
secondaryingress:
enabled: false
paths: []
apiVersion: "extensions/v1beta1"
labels: {}
annotations: {}
hostName:
tls:
backendconfig:
enabled: false
apiVersion: "extensions/v1beta1"
name:
labels: {}
annotations: {}
spec: {}
route:
enabled: false
labels: {}
annotations: {}
hostAliases: []
prometheus:
enabled: false
serviceMonitorAdditionalLabels: {}
scrapeInterval: 60s
scrapeEndpoint: /prometheus
alertingRulesAdditionalLabels: {}
alertingrules: []
prometheusRuleNamespace: ""
testEnabled: true
httpsKeyStore:
jenkinsHttpsJksSecretName: ''
enable: false
httpPort: 8081
path: "/var/jenkins_keystore"
fileName: "keystore.jks"
password: "password"
jenkinsKeyStoreBase64Encoded: |
/u3+7QAAAAIAAAABAAAAAQANamVua2luc2NpLmNvbQAAAW2r/b1ZAAAFATCCBP0wDgYKKwYBBAEq
AhEBAQUABIIE6QbCqasvoHS0pSwYqSvdydMCB9t+VNfwhFIiiuAelJfO5sSe2SebJbtwHgLcRz1Z
gMtWgOSFdl3bWSzA7vrW2LED52h+jXLYSWvZzuDuh8hYO85m10ikF6QR+dTi4jra0whIFDvq3pxe
TnESxEsN+DvbZM3jA3qsjQJSeISNpDjO099dqQvHpnCn18lyk7J4TWJ8sOQQb1EM2zDAfAOSqA/x
QuPEFl74DlY+5DIk6EBvpmWhaMSvXzWZACGA0sYqa157dq7O0AqmuLG/EI5EkHETO4CrtBW+yLcy
2dUCXOMA+j+NjM1BjrQkYE5vtSfNO6lFZcISyKo5pTFlcA7ut0Fx2nZ8GhHTn32CpeWwNcZBn1gR
pZVt6DxVVkhTAkMLhR4rL2wGIi/1WRs23ZOLGKtyDNvDHnQyDiQEoJGy9nAthA8aNHa3cfdF10vB
Drb19vtpFHmpvKEEhpk2EBRF4fTi644Fuhu2Ied6118AlaPvEea+n6G4vBz+8RWuVCmZjLU+7h8l
Hy3/WdUPoIL5eW7Kz+hS+sRTFzfu9C48dMkQH3a6f3wSY+mufizNF9U298r98TnYy+PfDJK0bstG
Ph6yPWx8DGXKQBwrhWJWXI6JwZDeC5Ny+l8p1SypTmAjpIaSW3ge+KgcL6Wtt1R5hUV1ajVwVSUi
HF/FachKqPqyLJFZTGjNrxnmNYpt8P1d5JTvJfmfr55Su/P9n7kcyWp7zMcb2Q5nlXt4tWogOHLI
OzEWKCac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y1wtog
hYAzODo1Jt59pcqqKJEas0C/lFJEB3frw4ImNx5fNlJYOpx+ijfQs9m39CevDq0=
agent:
enabled: true
defaultsProviderTemplate: ""
jenkinsUrl:
jenkinsTunnel:
kubernetesConnectTimeout: 5
kubernetesReadTimeout: 15
maxRequestsPerHostStr: "32"
namespace:
image: "jenkins/inbound-agent"
tag: "4.11.2-4"
workingDir: "/home/jenkins/agent"
nodeUsageMode: "NORMAL"
customJenkinsLabels: []
imagePullSecretName:
componentName: "jenkins-agent"
websocket: false
privileged: false
runAsUser:
runAsGroup:
resources:
requests:
cpu: "512m"
memory: "512Mi"
limits:
cpu: "512m"
memory: "512Mi"
alwaysPullImage: false
podRetention: "Never"
showRawYaml: true
volumes: []
workspaceVolume: {}
envVars: []
nodeSelector: {}
command:
args: "${computer.jnlpmac} ${computer.name}"
sideContainerName: "jnlp"
TTYEnabled: false
containerCap: 10
podName: "default"
idleMinutes: 0
yamlTemplate: ""
yamlMergeStrategy: "override"
connectTimeout: 100
annotations: {}
disableDefaultAgent: false
podTemplates: {}
# - name: python
# label: jenkins-python
# serviceAccount: jenkins
# containers:
# - name: python
# image: python:3
# command: "/bin/sh -c"
# args: "cat"
# ttyEnabled: true
# privileged: true
# resourceRequestCpu: "400m"
# resourceRequestMemory: "512Mi"
# resourceLimitCpu: "1"
# resourceLimitMemory: "1024Mi"
additionalAgents: {}
persistence:
enabled: true
existingClaim:
storageClass: jenkins-pv
annotations: {}
labels: {}
accessMode: "ReadWriteOnce"
size: "8Gi"
volumes:
mounts:
networkPolicy:
enabled: false
apiVersion: networking.k8s.io/v1
internalAgents:
allowed: true
podLabels: {}
namespaceLabels: {}
externalAgents: {}
rbac:
create: true
readSecrets: false
serviceAccount:
create: false
name: jenkins
annotations: {}
imagePullSecretName:
serviceAccountAgent:
create: false
name:
annotations: {}
imagePullSecretName:
backup:
enabled: false
componentName: "backup"
schedule: "0 2 * * *"
labels: {}
serviceAccount:
create: true
name:
annotations: {}
activeDeadlineSeconds: ""
image:
repository: "maorfr/kube-tasks"
tag: "0.2.0"
extraArgs: []
existingSecret: {}
env: []
resources:
requests:
memory: 1Gi
cpu: 1
limits:
memory: 1Gi
cpu: 1
destination: "s3://jenkins-data/backup"
onlyJobs: false
usePodSecurityContext: true
runAsUser: 1000
fsGroup: 1000
securityContextCapabilities: {}
checkDeprecation: true
awsSecurityGroupPolicies:
enabled: false
policies:
- name: ""
securityGroupIds: []
podSelector: {}
chart=jenkinsci/jenkins
(base) xiaoyu@localhost jenkinss-pv % helm install jenkins -n jenkins -f jenkins-values.yaml $chartNAME: jenkinsLAST DEPLOYED: Thu Apr 28 09:52:04 2022NAMESPACE: jenkinsSTATUS: deployedREVISION: 1NOTES:1. Get your 'admin' user password by running: kubectl exec --namespace jenkins -it svc/jenkins -c jenkins -- /bin/cat /run/secrets/chart-admin-password && echo2. Get the Jenkins URL to visit by running these commands in the same shell: echo http://127.0.0.1:8080 kubectl --namespace jenkins port-forward svc/jenkins 8080:80803. Login with the password from step 1 and the username: admin4. Configure security realm and authorization strategy5. Use Jenkins Configuration as Code by specifying configScripts in your values.yaml file, see documentation: http:///configuration-as-code and examples: https://github.com/jenkinsci/configuration-as-code-plugin/tree/master/demosFor more information on running Jenkins on Kubernetes, visit:https://cloud.google.com/solutions/jenkins-on-container-engineFor more information about Jenkins Configuration as Code, visit:https://jenkins.io/projects/jcasc/NOTE: Consider using a custom image with pre-installed plugins
上面已经提示部署完成了,接下来获取初始密码。
(base) xiaoyu@localhost jenkinss-pv % jsonpath="{.data.jenkins-admin-password}"(base) xiaoyu@localhost jenkinss-pv % secret=$(kubectl get secret -n jenkins jenkins -o jsonpath=$jsonpath)(base) xiaoyu@localhost jenkinss-pv % echo $(echo $secret | base64 --decode)By8cnPs8g8s1vO4MgCYRIw
得到初始密码之后,获取jenkins的URL。
(base) xiaoyu@localhost jenkinss-pv % jsonpath="{.spec.ports[0].nodePort}"(base) xiaoyu@localhost jenkinss-pv % NODE_PORT=$(kubectl get -n jenkins -o jsonpath=$jsonpath services jenkins)(base) xiaoyu@localhost jenkinss-pv % jsonpath="{.items[0].status.addresses[0].address}"(base) xiaoyu@localhost jenkinss-pv % NODE_IP=$(kubectl get nodes -n jenkins -o jsonpath=$jsonpath)(base) xiaoyu@localhost jenkinss-pv % echo http://$NODE_IP:$NODE_PORT/loginhttp://192.168.64.3:/login
获取jenkins的pod信息。
(base) xiaoyu@localhost jenkinss-pv % kubectl get pods -n jenkinsNAME READY STATUS RESTARTS AGEjenkins-0 2/2 Running 0 4h52m
同样配置在控制面板中我们也可以看到,注意切换命名空间。
配置接口转发。
(base) xiaoyu@localhost jenkinss-pv % kubectl -n jenkins port-forward jenkins-0 8080:8080Forwarding from 127.0.0.1:8080 -> 8080Forwarding from [::1]:8080 -> 8080
这样就可以访问到了,用户名admin,密码对应上面的查到的密码。
六、总结
本文介绍了两种jenkins的部署方式,其中基于k8s的部署方式是重点,后续的jenkins的实践也是基于在k8s上展开的。
|