k8s安装jenkins设置contextpath

1.部署jenkins

需要用到工具包,设置jenkins目录权限,方便安装插件

{ "kind": "Deployment", "apiVersion": "extensions/v1beta1", "metadata": { "name": "jenkins-autotest", "namespace": "ywxt", "selfLink": "/apis/extensions/v1beta1/namespaces/ywxt/deployments/jenkins-autotest", "uid": "70d153d8-a0ce-11ea-bf35-00163e000fe6", "labels": { "app-name": "jenkins-autotest" } }, "spec": { "replicas": 1, "selector": { "matchLabels": { "app-name": "jenkins-autotest" } }, "template": { "metadata": { "creationTimestamp": null, "labels": { "app-name": "jenkins-autotest" } }, "spec": { "volumes": [ { "name": "localtime", "hostPath": { "path": "/etc/localtime", "type": "" } }, { "name": "jenkins-home", "hostPath": { "path": "/data/jenkins", "type": "" } } ], "initContainers": [ { "name": "fix-permissions", "image": "*****/busybox:latest", "command": [ "sh", "-c", "chmod -R 777 /var/jenkins_home" ], "resources": {}, "volumeMounts": [ { "name": "jenkins-home", "mountPath": "/var/jenkins_home" } ], "terminationMessagePath": "/dev/termination-log", "terminationMessagePolicy": "File", "imagePullPolicy": "Always", "securityContext": { "privileged": true } } ], "containers": [ { "name": "jenkins", "image": "****/jenkins:lts-centos", "ports": [ { "name": "web", "containerPort": 8080, "protocol": "TCP" }, { "name": "agent", "containerPort": 50000, "protocol": "TCP" } ], "env": [ { "name": "JAVA_OPTS", "value": "-Duser.timezone=Asia/Shanghai -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85" }, { "name": "JENKINS_OPTS", "value": "--prefix=/jenkins" } ], "resources": {}, "volumeMounts": [ { "name": "jenkins-home", "mountPath": "/var/jenkins_home" } ], "terminationMessagePath": "/dev/termination-log", "terminationMessagePolicy": "File", "imagePullPolicy": "IfNotPresent", "securityContext": { "privileged": true } } ], "restartPolicy": "Always", "terminationGracePeriodSeconds": 30, "dnsPolicy": "ClusterFirst", "securityContext": {}, "schedulerName": "default-scheduler" } }, "strategy": { "type": "RollingUpdate", "rollingUpdate": { "maxUnavailable": 0, "maxSurge": 1 } }, "revisionHistoryLimit": 10, "progressDeadlineSeconds": 600 } }

2.设置contextpath

查看启动文件/usr/local/bin/jenkins.sh

 #! /bin/bash -e: "${JENKINS_WAR:="/usr/share/jenkins/jenkins.war"}": "${JENKINS_HOME:="/var/jenkins_home"}": "${COPY_REFERENCE_FILE_LOG:="${JENKINS_HOME}/copy_reference_file.log"}": "${REF:="/usr/share/jenkins/ref"}"touch "${COPY_REFERENCE_FILE_LOG}" || { echo "Can not write to ${COPY_REFERENCE_FILE_LOG}. Wrong volume permissions?"; exit 1; }echo "--- Copying files at $(date)" >> "$COPY_REFERENCE_FILE_LOG"find "${REF}" \( -type f -o -type l \) -exec bash -c '. /usr/local/bin/jenkins-support; for arg; do copy_reference_file "$arg"; done' _ {} +# if `docker run` first argument start with `--` the user is passing jenkins launcher argumentsif [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then  # read JAVA_OPTS and JENKINS_OPTS into arrays to avoid need for eval (and associated vulnerabilities)  java_opts_array=()  while IFS= read -r -d '' item; do    java_opts_array+=( "$item" )  done < <([[ $JAVA_OPTS ]] && xargs printf '%s\0' <<<"$JAVA_OPTS")  readonly agent_port_property='jenkins.model.Jenkins.slaveAgentPort'  if [ -n "${JENKINS_SLAVE_AGENT_PORT:-}" ] && [[ "${JAVA_OPTS:-}" != *"${agent_port_property}"* ]]; then    java_opts_array+=( "-D${agent_port_property}=${JENKINS_SLAVE_AGENT_PORT}" )  fi

jenkins的启动配置参数通过JENKINS_OPTS进行传递。JVM 启动参数通过JAVA_OPTS 进行设置。

设置环境变量JENKINS_OPTS.

{   "name": "JENKINS_OPTS",   "value": "--prefix=/jenkins"}

进入容器查看启动命令:

bash-4.4$ ps aux|grep javajenkins      7 45.0  1.1 35651108 379492 ?     Sl   03:16   0:22 java -Duser.home=/var/jenkins_home -Duser.timezone=Asia/Shanghai -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 -Djenkins.model.Jenkins.slaveAgentPort=50000 -jar /usr/share/jenkins/jenkins.war --prefix=/jenkins

你可能感兴趣的:(k8s安装jenkins设置contextpath)