Deployments是在Kubernetes 1.2版本增加的特性,作为对于pod的控制,Deployments实现了声明式的应用发布和升级,保证了应用的高可用性和快速回滚的能力。在Kubernetes 1.8时相关API移至apps/v1beta2,在Kubernetes 1.9中整合至apps/v1,随着环境中的Kubernetes的升级,原有API的废弃导致Deployment的相应yaml文件需要修改,这篇文章以旧版的Prometheus的Deployment的修改为例,介绍Deployments修改需要注意的事项。
事前准备
本文示例中准备了Kubernetes 1.17的环境,环境的准备方法可参考如下Easyapck下的Ansible一键脚本。
[root@host131 ansible]# kubectl version
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:20:10Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:12:17Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
[root@host131 ansible]#
[root@host131 ansible]# kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
192.168.163.131 Ready <none> 18m v1.17.0 192.168.163.131 <none> CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 docker://18.9.7
[root@host131 ansible]#
Deployment示例准备
如下是Deployment在beta1阶段的Yaml文件示例
[root@host131 prometheus]# cat prometheus-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: prometheus-deployment
namespace: monitoring
spec:
replicas: 1
template:
metadata:
labels:
app: prometheus-server
spec:
containers:
- name: prometheus
image: prom/prometheus:v2.12.0
args:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus/"
ports:
- containerPort: 9090
volumeMounts:
- name: prometheus-config-volume
mountPath: /etc/prometheus/
- name: prometheus-storage-volume
mountPath: /prometheus/
volumes:
- name: prometheus-config-volume
configMap:
defaultMode: 420
name: prometheus-server-conf
- name: prometheus-storage-volume
emptyDir: {}
[root@host131 prometheus]#
Y