我目前正在为OpenShift设计模板,并且在我初始化实例化应用程序时,我的ImageChange触发器被删除了。我的模板包含以下对象
我想这条路线是不相关的,但是到目前为止,它看起来是这样(为了更好地概述,我将对象分离开来,但是它们都是我模板中的所有项目)
ImageStream
- kind: ImageStream
apiVersion: v1
metadata:
labels:
app: my-app
name: my-app
namespace: ${IMAGE_NAMESPACE}
BuildConfig
- kind: BuildConfig
apiVersion: v1
metadata:
labels:
app: my-app
deploymentconfig: my-app
name: my-app
namespace: ${IMAGE_NAMESPACE}
selfLink: /oapi/v1/namespaces/${IMAGE_NAMESPACE}/buildconfigs/my-app
spec:
runPolicy: Serial
source:
git:
ref: pre-prod
uri: 'ssh://git@git.myreopo.net:port/project/my-app.git'
sourceSecret:
name: git-secret
type: Git
strategy:
type: Source
sourceStrategy:
env:
- name: HTTP_PROXY
value: 'http://user:password@proxy.com:8080'
- name: HTTPS_PROXY
value: 'http://user:password@proxy.com:8080'
- name: NO_PROXY
value: .something.net
from:
kind: ImageStreamTag
name: 'nodejs:8'
namespace: openshift
output:
to:
kind: ImageStreamTag
name: 'my-app:latest'
namespace: ${IMAGE_NAMESPACE}
服务
- kind: Service
apiVersion: v1
metadata:
name: my-app
labels:
app: my-app
spec:
selector:
deploymentconfig: my-app
ports:
- name: 8080-tcp
port: 8080
protocol: TCP
targetPort: 8080
sessionAffinity: None
type: ClusterIP
DeploymentConfig
现在DeploymentConfig中已经很奇怪的是,在spec.template.spec.containers [0] .image下,我必须指定存储库的完整路径以使其正常工作,否则在提取图像时会出错。 (即使文档说my-app:latest是正确的)
- kind: DeploymentConfig
apiVersion: v1
metadata:
labels:
app: my-app
deploymentconfig: my-app
name: my-app
namespace: ${IMAGE_NAMESPACE}
selfLink: /oapi/v1/namespaces/${IMAGE_NAMESPACE}/deploymentconfigs/my-app
spec:
selector:
app: my-app
deploymentconfig: my-app
strategy:
type: Rolling
rollingParams:
intervalSeconds: 1
maxSurge: 25%
maxUnavailability: 25%
timeoutSeconds: 600
updatePeriodSeconds: 1
replicas: 1
template:
metadata:
labels:
app: my-app
deploymentconfig: my-app
spec:
containers:
- name: my-app-container
image: "${REPOSITORY_IP}:${REPOSITORY_PORT}/${IMAGE_NAMESPACE}/my-app:latest"
imagePullPolicy: Always
ports:
- containerPort: 8080
protocol: TCP
- containerPort: 8081
protocol: TCP
env:
- name: MONGODB_USERNAME
valueFrom:
secretKeyRef:
name: my-app-database
key: database-user
- name: MONGODB_PASSWORD
valueFrom:
secretKeyRef:
name: my-app-database
key: database-password
- name: MONGODB_DATABASE
value: "myapp"
- name: ROUTE_PATH
value: /my-app
- name: MONGODB_AUTHDB
value: "myapp"
- name: MONGODB_PORT
value: "27017"
- name: HTTP_PORT
value: "8080"
- name: HTTPS_PORT
value: "8082"
restartPolicy: Always
dnsPolicy: ClusterFirst
triggers:
- type: ImageChange
imageChangeParams:
automatic: true
from:
kind: ImageStreamTag
name: 'my-app:latest'
namespace: ${IMAGE_NAMESPACE}
containerNames:
- my-app-container
- type: ConfigChange
我使用部署应用程序
oc process -f ./openshift/template.yaml ..Parameters... | oc apply -f -
但是当我使用oc new-app时,结果是一样的。
奇怪的是。该应用程序已部署并且运行良好,但是映像更改将无效。因此,我导出了DeploymentConfig,发现它缺少ImageChangeTrigger,而触发器部分处于
triggers:
- type: ConfigChange
起初,我认为这是由于以下事实:当我尝试应用DeploymentConfig时,可能尚未构建完成,因此我首先创建了一个构建并等待其完成。之后,我部署了其余的应用程序(Service,Route,DeploymentConfig)。结果是一样的。如果我使用Webgui并从中更改DeploymentConfig
为此,填写名称空间,应用程序和标签(最新),然后点击应用所有应有的功能。我只是不知道为什么最初会忽略触发器。如果有人知道我错了,那就太好了
我使用的版本是
oc:v3.9.0
kubernetes:1.6.1版
openshift v3.6.173.0.140
答案 0 :(得分:1)
好的,答案很简单。原来,这只是DeploymentConfig的yaml文件中的缩进错误。代替
dnsPolicy: ClusterFirst
restartPolicy: Always
terminationGracePeriodSeconds: 30
triggers:
- type: ImageChange
imageChangeParams:
automatic: true
containerNames:
- alpac-studio-container
from:
kind: ImageStreamTag
name: alpac-studio:latest
- type: ConfigChange
必须是
dnsPolicy: ClusterFirst
restartPolicy: Always
terminationGracePeriodSeconds: 30
triggers:
- type: ImageChange
imageChangeParams:
automatic: true
containerNames:
- alpac-studio-container
from:
kind: ImageStreamTag
name: alpac-studio:latest
- type: ConfigChange
因此,触发器必须与例如模板和策略