我希望我的部署配置使用作为构建配置输出的图像。
我目前正在使用这样的东西:
- 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(08/23/2017): 如果这有助于其他人,这里是解决方案的摘要。
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
之前至少触发一次部署。到目前为止,我是:
automatic
设为true
automatic
更改为false
我最初尝试使用此手动部署作为非开发人员进入Web控制台并进行部署的一种方式。但是此要求已被删除,因此每次构建触发器部署对我们来说都很合适。构建可以在不同的分支上构建,然后以不同的方式标记图像。然后,部署可以使用适当标记的图像。
希望有所帮助!
答案 0 :(得分:2)
您是手动构建资源定义吗?
如果由于某种原因确实需要将其设置为两个步骤,那么使用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
。你可以做后者,但不能做你现在的做法。