IaM*_*CuP 3 google-cloud-platform kubernetes google-kubernetes-engine
我一直在使用init-containers,因为它们变得可用并且发现它们非常有用.我的核心映像(下面作为web-dev)没有太大变化,但我的init-container映像(下面作为web-data-dev)确实经常更改.
init-container使用带有版本号的容器映像.我将此版本号更改为最新值,然后执行kubectl apply -f deployment.yaml
例如,在运行kubectl apply之前,我将eu.gcr.io/project/web-data-dev:187更改为eu.gcr.io/project/web-data-dev:188.
然而,当我这样做时,没有发生部署,如果我对init-container使用的映像进行任何更改,部署仍然不会发生.我认为这是因为没有检测到init-container更改.
然后我试图在图像字段中放入一些垃圾,如下所示:"image":"thisIsNotAnImage"并再次运行kubectl apply -f,但仍未应用更新.
我的问题是 - 如何使用kubectl apply -f检测init-container中的图像标签更改?我做错了什么,这是一个错误,还是这还没有实现,因为init-containers是Alpha?
完整部署YAML如下.
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: web-deployment
spec:
replicas: 1
strategy:
rollingUpdate:
maxUnavailable: 0
template:
metadata:
labels:
app: web
tier: frontend
annotations:
pod.alpha.kubernetes.io/init-containers: '[
{
"name": "initialiser1",
"image": "eu.gcr.io/project/web-data-dev:187",
"command": ["cp", "-r", "/data-in/", "/opt/"],
"volumeMounts": [
{
"name": "file-share",
"mountPath": "/opt/"
}
]
}
]'
spec:
containers:
- image: eu.gcr.io/project/web-dev:20
name: web
resources:
requests:
cpu: 10m
memory: 40Mi
ports:
- containerPort: 80
name: http
- containerPort: 443
name: https
volumeMounts:
- name: file-share
mountPath: /opt/
volumes:
- name: file-share
emptyDir: {}
Run Code Online (Sandbox Code Playgroud)
小智 6
如果您使用的是Kubernetes 1.4,请尝试更改pod.alpha.kubernetes.io/init-containers
为pod.beta.kubernetes.io/init-containers
.
我在GitHub上找不到合适的问题,但这两个注释的行为是不同的.我可以kubectl apply -f
使用第二个,部署将更新.
您可以使用以下示例进行测试:
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: nginx
spec:
template:
metadata:
labels:
app: nginx
annotations:
pod.beta.kubernetes.io/init-containers: '[
{
"name": "install",
"image": "busybox",
"command": ["/bin/sh", "-c", "echo foo > /work-dir/index.html"],
"volumeMounts": [
{
"name": "workdir",
"mountPath": "/work-dir"
}
]
}
]'
spec:
volumes:
- name: workdir
emptyDir: {}
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: workdir
mountPath: /usr/share/nginx/html
Run Code Online (Sandbox Code Playgroud)
尝试改变foo
到bar
和看到的结果:
$ cat nginx.yaml | kubectl apply -f -
deployment "nginx" created
$ curl $(minikube service nginx --url)
Waiting, endpoint for service is not ready yet...
foo
$ cat nginx.yaml | sed -e 's/foo/bar/g' | kubectl apply -f -
deployment "nginx" configured
$ curl $(minikube service nginx --url)
Waiting, endpoint for service is not ready yet...
bar
Run Code Online (Sandbox Code Playgroud)
使用相同的东西pod.alpha.kubernetes.io/init-containers
:
$ curl $(minikube service nginx --url)
Waiting, endpoint for service is not ready yet...
foo
$ cat nginx.yaml | sed -e 's/foo/bar/g' | kubectl apply -f -
deployment "nginx" configured
$ curl $(minikube service nginx --url)
foo
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1236 次 |
最近记录: |