如何在 Google Container Engine 上更新 Kubernetes 部署?
How to update a Kubernetes deployment on Google Container Engine?
我遵循了一些指南,并且 CI 设置了 Google 容器引擎和 Google 容器注册表。问题是我的更新没有应用到部署中。
所以这是我的 deployment.yml,其中包含 Kubernetes 服务和部署:
apiVersion: v1
kind: Service
metadata:
name: my_app
labels:
app: my_app
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 3000
selector:
app: my_app
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my_app
spec:
replicas: 1
template:
metadata:
labels:
app: my_app
spec:
containers:
- name: node
image: gcr.io/me/my_app:latest
ports:
- containerPort: 3000
resources:
requests:
memory: 100
- name: phantom
image: docker.io/wernight/phantomjs:2.1.1
command: ["phantomjs", "--webdriver=8910", "--web-security=no", "--load-images=false", "--local-to-remote-url-access=yes"]
ports:
- containerPort: 8910
resources:
requests:
memory: 1000
作为我的 CI 过程的一部分,我 运行 一个脚本更新 google 云注册表中的图像,然后 运行s kubectl apply -f /deploy/deployment.yml
。两项任务均成功,我收到部署和服务已更新的通知:
2016-09-28T14:37:26.375Zgoogleclouddeploymentservice "my_app" configured
2016-09-28T14:37:27.370Zgoogleclouddeploymentdeployment "my_app" configured
因为我在我的图像上包含了 :latest
标签,所以我认为图像应该是 downloaded each time the deployment is updated. Acccording to the docs,RollingUpdate
也应该是默认策略。
但是,当我 运行 我的 CI 脚本更新部署时 - 更新后的图像未下载且更改未应用。我错过了什么?我假设因为 deployment.yml
中没有任何变化,所以没有应用任何更新。如何让 Kubernetes 下载更新后的映像并使用 RollingUpdate
部署它?
您可以通过更改任何字段(例如标签)来强制更新部署。所以就我而言,我只是在 CI 脚本的末尾添加了这个:
kubectl patch deployment fb-video-extraction -p \
"{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
我们最近发布了一篇 technical overview 关于如何在 GKE 中实施我们称之为 GitOps 方法的文章。
您需要做的就是配置 GCR 构建器以从 Github 和 运行 构建中获取代码更改,然后在集群中安装 Weave Cloud 代理并连接到 YAML 所在的存储库文件已存储,代理将负责使用新图像更新存储库并将更改应用到集群。
有关更高级的概述,另请参阅:
免责声明:我是 Kubernetes 贡献者和 Weaveworks 员工。我们构建开源和商业工具,帮助人们更快地使用 Kubernetes 投入生产。
我遵循了一些指南,并且 CI 设置了 Google 容器引擎和 Google 容器注册表。问题是我的更新没有应用到部署中。
所以这是我的 deployment.yml,其中包含 Kubernetes 服务和部署:
apiVersion: v1
kind: Service
metadata:
name: my_app
labels:
app: my_app
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 3000
selector:
app: my_app
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my_app
spec:
replicas: 1
template:
metadata:
labels:
app: my_app
spec:
containers:
- name: node
image: gcr.io/me/my_app:latest
ports:
- containerPort: 3000
resources:
requests:
memory: 100
- name: phantom
image: docker.io/wernight/phantomjs:2.1.1
command: ["phantomjs", "--webdriver=8910", "--web-security=no", "--load-images=false", "--local-to-remote-url-access=yes"]
ports:
- containerPort: 8910
resources:
requests:
memory: 1000
作为我的 CI 过程的一部分,我 运行 一个脚本更新 google 云注册表中的图像,然后 运行s kubectl apply -f /deploy/deployment.yml
。两项任务均成功,我收到部署和服务已更新的通知:
2016-09-28T14:37:26.375Zgoogleclouddeploymentservice "my_app" configured
2016-09-28T14:37:27.370Zgoogleclouddeploymentdeployment "my_app" configured
因为我在我的图像上包含了 :latest
标签,所以我认为图像应该是 downloaded each time the deployment is updated. Acccording to the docs,RollingUpdate
也应该是默认策略。
但是,当我 运行 我的 CI 脚本更新部署时 - 更新后的图像未下载且更改未应用。我错过了什么?我假设因为 deployment.yml
中没有任何变化,所以没有应用任何更新。如何让 Kubernetes 下载更新后的映像并使用 RollingUpdate
部署它?
您可以通过更改任何字段(例如标签)来强制更新部署。所以就我而言,我只是在 CI 脚本的末尾添加了这个:
kubectl patch deployment fb-video-extraction -p \
"{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
我们最近发布了一篇 technical overview 关于如何在 GKE 中实施我们称之为 GitOps 方法的文章。
您需要做的就是配置 GCR 构建器以从 Github 和 运行 构建中获取代码更改,然后在集群中安装 Weave Cloud 代理并连接到 YAML 所在的存储库文件已存储,代理将负责使用新图像更新存储库并将更改应用到集群。
有关更高级的概述,另请参阅:
免责声明:我是 Kubernetes 贡献者和 Weaveworks 员工。我们构建开源和商业工具,帮助人们更快地使用 Kubernetes 投入生产。