我希望我的部署配置使用作爲構建配置輸出的圖像。如何在OpenShift的部署配置中使用圖像流
我目前使用的是這樣的:
- 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: {}
我不得不硬編碼集成泊塢窗註冊表的IP地址;否則Kubernetes/OpenShift無法找到要下拉的圖像。我想不硬編碼集成泊塢窗註冊表的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知道在綜合泊塢窗,以查找圖像:
- 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
- 手動,後來引發的部署(雖然我沒有驗證這是否部署過時的,過時的圖像)
我最初嘗試使用這個manu部署作爲非開發人員進入Web控制檯並進行部署的一種方式。但是這個要求已經被刪除,所以每次構建觸發器部署對我們來說都很好。構建可以在不同的分支構建,然後以不同的方式標記圖像。部署可以使用恰當標記的圖像。
希望有幫助!
感謝您的反饋。我最初確實使用'oc new-app'來輸出一個我已經建立的模板。我確實有一個我沒有發佈的構建配置YAML。但如果你認爲這很重要,我可以發佈它。我通常運行'oc create -f ...',並且創建並運行構建,映像流,部署,服務和路由。我正在嘗試進行此修改以支持單獨的分段和生產實例。暫存實例工作正常,因爲觸發器以某種方式使Openshift/Kubernetes找到正確的圖像。我不想要生產實例... –
...自動觸發。因此,當我在沒有觸發器的情況下進行新的部署配置時,OpenShift/Kubernetes無法再查找從構建配置構建的映像,因爲它看起來像Docker Hub。 –
而'python3'是從'oc new-app'創建的模板剩餘的。 'command'腳本似乎即使使用'入口點'也能運行服務器。再次感謝,請讓我知道,如果你看到其他任何可疑的東西! :) –