k8s安裝jenkins設(shè)置contextpath

1.部署jenkins

需要用到工具包,設(shè)置jenkins目錄權(quán)限,方便安裝插件

{ "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.設(shè)置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的啟動配置參數(shù)通過JENKINS_OPTS進(jìn)行傳遞。JVM 啟動參數(shù)通過JAVA_OPTS 進(jìn)行設(shè)置。

設(shè)置環(huán)境變量JENKINS_OPTS.

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

進(jìn)入容器查看啟動命令:

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容