Kubernetes本地的配置管理工具,相当于轻量版的helm。
官网地址:Kustomize - Kubernetes native configuration management
以后我们公司自己部署的一些中间件等,可以封装为 kustomize 管理的文件结构。 只需要
kubectl apply -k
即可快速部署不同环境应用
#service.yaml
kind: Service
apiVersion: v1
metadata:
name: the-service
spec:
selector:
deployment: hello
type: ClusterIP
ports:
- protocol: TCP
port: 8666
targetPort: 8080
#kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
metadata:
name: arbitrary
# Example configuration for the webserver
# at https://github.com/monopole/hello
commonLabels:
app: hello # 构建出来的每个资源上都有app=hello标签
resources:
- deployment.yaml
- service.yaml
- configMap.yaml
#configMap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
data:
altGreeting: "Good Morning!"
enableRisky: "false"
#deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: the-deployment
spec:
replicas: 3
selector:
matchLabels:
deployment: hello
template:
metadata:
labels:
deployment: hello
spec:
containers:
- name: the-container
image: monopole/hello:1
command: ["/hello",
"--port=8080",
"--enableRiskyFeature=$(ENABLE_RISKY)"]
ports:
- containerPort: 8080
env:
- name: ALT_GREETING
valueFrom:
configMapKeyRef:
name: the-map
key: altGreeting
- name: ENABLE_RISKY
valueFrom:
configMapKeyRef:
name: the-map
key: enableRisky
kubectl apply -k demo/
base
环境。其他环境层可只定义变量覆盖
#production/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: production-
commonLabels:
variant: production
org: acmeCorporation
commonAnnotations:
note: Hello, I am production!
bases:
- ../../base
patchesStrategicMerge:
- deployment.yaml
#production/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: the-deployment
spec:
replicas: 10
## 只需要定义可变部分
#staging/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: staging- #所有资源的前缀
commonLabels: #所有资源的标签
variant: staging
org: acmeCorporation
commonAnnotations: #所有资源的注解
note: Hello, I am staging!
bases:
- ../../base #基础配置的位置
patchesStrategicMerge:
- map.yaml #需要额外引入部署的内容,如果引入的内容基础内容有配置,则使用这个最新的
#staging/map.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
data:
altGreeting: "Have a pineapple!"
enableRisky: "true"
kubectl apply -k overlays/staging -n hello #可以在部署的时候统一制定名称空间
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。