gpt4 book ai didi

openshift - 如何在 OpenShift 的部署配置中使用图像流

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

我希望我的部署配置使用作为构建配置输出的镜像。

我目前正在使用这样的东西:

- apiVersion: v1
kind: DeploymentConfig
metadata:
annotations:
openshift.io/generated-by: OpenShiftNewApp
creationTimestamp: null
labels:
app: myapp
name: myapp
spec:
replicas: 1
selector:
app: myapp
deploymentconfig: myapp
strategy:
resources: {}
template:
metadata:
annotations:
openshift.io/container.myapp.image.entrypoint: '["python3"]'
openshift.io/generated-by: OpenShiftNewApp
creationTimestamp: null
labels:
app: myapp
deploymentconfig: myapp
spec:
containers:
- name: myapp
image: 123.123.123.123/myproject/myapp-staging:latest
resources: {}
command:
- scripts/start_server.sh
ports:
- containerPort: 8000
test: false
triggers: []
status: {}

我必须对集成 docker 注册表的 IP 地址进行硬编码;否则 Kubernetes/OpenShift 无法找到要下拉的镜像。我不想对集成 docker 注册表的 IP 地址进行硬编码,而是使用如下所示的内容:

- apiVersion: v1
kind: DeploymentConfig
metadata:
annotations:
openshift.io/generated-by: OpenShiftNewApp
creationTimestamp: null
labels:
app: myapp
name: myapp
spec:
replicas: 1
selector:
app: myapp
deploymentconfig: myapp
strategy:
resources: {}
template:
metadata:
annotations:
openshift.io/container.myapp.image.entrypoint: '["python3"]'
openshift.io/generated-by: OpenShiftNewApp
creationTimestamp: null
labels:
app: myapp
deploymentconfig: myapp
spec:
containers:
- name: myapp
from:
kind: "ImageStreamTag"
name: "myapp-staging:latest"
resources: {}
command:
- scripts/start_server.sh
ports:
- containerPort: 8000
test: false
triggers: []
status: {}

但这会导致 Kubernetes/OpenShift 提示:

The DeploymentConfig "myapp" is invalid.
spec.template.spec.containers[0].image: required value

如何将构建配置的输出指定为要在部署配置中使用的镜像?

感谢您的宝贵时间!

此外,奇怪的是,如果我使用触发器将部署配置链接到构建配置,Kubernetes/OpenShift 就会知道在集成的 docker 中查找镜像:

- apiVersion: v1
kind: DeploymentConfig
metadata:
annotations:
openshift.io/generated-by: OpenShiftNewApp
creationTimestamp: null
labels:
app: myapp-staging
name: myapp-staging
spec:
replicas: 1
selector:
app: myapp-staging
deploymentconfig: myapp-staging
strategy:
resources: {}
template:
metadata:
annotations:
openshift.io/container.myapp.image.entrypoint: '["python3"]'
openshift.io/generated-by: OpenShiftNewApp
creationTimestamp: null
labels:
app: myapp-staging
deploymentconfig: myapp-staging
spec:
containers:
- name: myapp-staging
image: myapp-staging:latest
resources: {}
command:
- scripts/start_server.sh
ports:
- containerPort: 8000
test: false
triggers:
- type: "ImageChange"
imageChangeParams:
automatic: true
containerNames:
- myapp-staging
from:
kind: ImageStreamTag
name: myapp-staging:latest
status: {}

但我不想要自动触发...

更新 1(2016 年 11 月 21 日):配置触发器但禁用触发器(因此手动触发部署),仍然使部署无法找到镜像:

$ oc describe pod myapp-1-oodr5
Name: myapp-1-oodr5
Namespace: myproject
Security Policy: restricted
Node: node.url/123.123.123.123
Start Time: Mon, 21 Nov 2016 09:20:26 -1000
Labels: app=myapp
deployment=myapp-1
deploymentconfig=myapp
Status: Pending
IP: 123.123.123.123
Controllers: ReplicationController/myapp-1
Containers:
myapp:
Container ID:
Image: myapp-staging:latest
Image ID:
Port: 8000/TCP
Command:
scripts/start_server.sh
State: Waiting
Reason: ImagePullBackOff
Ready: False
Restart Count: 0
Volume Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-goe98 (ro)
Environment Variables:
ALLOWED_HOSTS: myapp-myproject.url
Conditions:
Type Status
Ready False
Volumes:
default-token-goe98:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-goe98
QoS Tier: BestEffort
Events:
FirstSeen LastSeen Count From SubobjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
42s 42s 1 {scheduler } Scheduled Successfully assigned myapp-1-oodr5 to node.url
40s 40s 1 {kubelet node.url} implicitly required container POD Pulled Container image "openshift3/ose-pod:v3.1.1.7" already present on machine
40s 40s 1 {kubelet node.url} implicitly required container POD Created Created with docker id d3318e880e4a
40s 40s 1 {kubelet node.url} implicitly required container POD Started Started with docker id d3318e880e4a
40s 24s 2 {kubelet node.url} spec.containers{myapp} Pulling pulling image "myapp-staging:latest"
38s 23s 2 {kubelet node.url} spec.containers{myapp} Failed Failed to pull image "myapp-staging:latest": Error: image library/myapp-staging:latest not found
35s 15s 2 {kubelet node.url} spec.containers{myapp} Back-off Back-off pulling image "myapp-staging:latest"

更新 2(2017 年 8 月 23 日):如果这对其他人有帮助,这里是解决方案的摘要。

triggers:    
- type: "ImageChange"
imageChangeParams:
automatic: true # this is required to link the build and deployment
containerNames:
- myapp-staging
from:
kind: ImageStreamTag
name: myapp-staging:latest

将触发器和automatic 设置为true 后,部署应使用内部注册表中的构建镜像。

与使构建不触发部署相关的其他评论涉及想要从内部注册表手动部署镜像的单独要求。以下是有关该部分的更多信息:

在将automatic 设置为false 之前,构建需要至少触发一次部署。到目前为止,我是:

  1. 自动设置为true
  2. 启动构建和部署
  3. 部署完成后,手动将automatic更改为false
  4. 稍后手动触发部署(尽管我没有验证这是否部署了旧的、过时的镜像)

我最初尝试使用此手动部署作为非开发人员进入 Web 控制台并进行部署的一种方式。但此要求已被删除,因此每次构建触发器部署现在对我们来说都很好。构建可以在不同的分支上构建,然后以不同的方式标记图像。然后部署就可以使用适当标记的图像。

希望有帮助!

最佳答案

您是否手动构建资源定义?

如果您出于某种原因确实需要将其设置为两个步骤,那么先使用 oc new-build ,然后再使用 oc new-app 会更容易。如果您只想一次性设置构建和部署,只需使用 oc new-app 即可。

例如,要一次性设置构建和部署,请使用:

oc new-app --name myapp <repository-url>

要分两步完成,请使用:

oc new-build --name myapp <repository-url>
oc new-app myapp

如果您仍然宁愿使用手动创建的资源,至少使用带有 --dry-run -o yaml 选项的单步变体来查看它将为图像流创建什么,以及构建和部署配置。这样你就可以从中学习如何去做。您当前缺少的部分是图像流。

顺便说一句。您将入口点设置为 python3 看起来有点可疑。这是非常不寻常的。您现在想要做什么,看起来您可能正在尝试以一种不适合 OpenShift 工作方式的方式做某事。 OpenShift 主要针对长时间运行的进程,而不是用于执行单个 docker run。您可以执行后者,但不能执行您当前的操作方式。

关于openshift - 如何在 OpenShift 的部署配置中使用图像流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40597903/

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