gpt4 book ai didi

docker - 有没有办法更新在Kubernetes中运行的Jenkins?

转载 作者:行者123 更新时间:2023-12-02 12:12:05 29 4
gpt4 key购买 nike

我正在尝试在Kubernetes中运行Jenkins,但Jenkins的版本已过时。它说我需要Kubernetes插件的至少2.138.4版本。

我正在使用来自Docker中心的this jenkins镜像(“jenkins / jenkins:lts”)。但是当我尝试在Kubernetes中运行它时,它说版本是2.60.3。我以前使用的是Jenkins(2.60.3)的旧版本,但是我更新了Dockerfile以使用最新的镜像。之后,我再次构建镜像并将其扔到Kubernetes。在重新部署它们之前,我什至删除了我的Kubernetes部署和服务。
我目前正在使用Minikube的开发环境中工作。

Dockerfile:

FROM jenkins/jenkins:lts

ENV JENKINS_USER admin
ENV JENKINS_PASS admin

# Skip initial setup
ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false


COPY plugins.txt /usr/share/jenkins/plugins.txt
RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/plugins.txt
USER root
RUN apt-get update \
&& apt-get install -qqy apt-transport-https ca-certificates curl gnupg2 software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
RUN apt-get update -qq \
&& apt-get install docker-ce -y
RUN usermod -aG docker jenkins
RUN apt-get clean
RUN curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
USER jenkins

Kubernetes部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
containers:
- name: jenkins
image: mikemanders/my-jenkins-image:1.0
env:
- name: JAVA_OPTS
value: -Djenkins.install.runSetupWizard=false
ports:
- name: http-port
containerPort: 8080
- name: jnlp-port
containerPort: 50000
volumeMounts:
- name: jenkins-home
mountPath: /var/jenkins_home
volumes:
- name: jenkins-home
emptyDir: {}


和Kubernetes服务:
apiVersion: v1
kind: Service
metadata:
name: jenkins
spec:
type: NodePort
selector:
app: jenkins
ports:
- port: 8080
targetPort: 8080


我认为我的Kubernetes配置很好,所以我猜想它与Docker有关吗?

我在这里想念/做错了什么?

最佳答案

TL; DR

update a deployment,您需要基于新Docker版本的新Jenkins图像:

docker build -t mikemanders/my-jenkins-image:1.1 .
docker push mikemanders/my-jenkins-image
kubectl set image deployment/jenkins mikemanders/my-jenkins-image=1.1 --record
Kubernetes部署 images而不是 dockerfiles
根据 Images man

You create your Docker image and push it to a registry before referring to it in a Kubernetes pod.

The image property of a container supports the same syntax as the docker command does, including private registries and tags.



因此,您需要部署镜像。

更新您的图片

要在注册表中更新图像,请使用 docker build -tdocker push:
docker build -t mikemanders/my-jenkins-image:1.1
docker push mikemanders/my-jenkins-image

它将使用更新的 jenkins/jeinkis:lts重建图像。然后图像将被上传到 container registry

问题在于您在更新集群之前要更新镜像版本(例如 1.0-> 1.1)。

关于docker - 有没有办法更新在Kubernetes中运行的Jenkins?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61484545/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com