deployment-patch.yaml
文章插图
文章插图
---apiVersion: v1kind: Namespacemetadata: name: demonamespace.yaml
### 文章首发于博客园 https://www.cnblogs.com/wade-xu/p/16839829.html
最后我们看 dev/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1kind: Kustomizationresources:- ../_commonnamespace: democommonLabels: app: demo-appreplicas:- count: 1 name: demo-appconfigMapGenerator:- files: - config.json name: demo-app-configpatches:- patch: |- - op: replace path: /metadata/name value: demo-app target: name: NAME_PLACEHOLDERpatchesStrategicMerge:- deployment-patch.yamlimages:- name: wadexu007/demo newTag: 1.0.0dev env 里面将replicas设置成1, 用config.json 生成 configMap
文章插图
文章插图
{ "SOME_CONFIG": "/demo/path"}config.json
deployment-patch.yaml 里面也将container resource request/limit 配置设置小一点 , 采用 patchesStrategicMerge 与 common 和 base里面的deployment资源合并 。
文章插图
文章插图
apiVersion: apps/v1kind: Deploymentmetadata: name: NAME_PLACEHOLDERspec: template: spec: containers: - name: app resources: limits: cpu: 1 memory: 1Gi requests: cpu: 200m memory: 256Mideployment-patch.yaml
另外还采用了 patch 的方式,改了每个资源的name --> demo-app
以及images 替换了原来的 image name and tag.
kustomize 命令如下
kustomize build demo-manifests/services/demo-app/dev > demo-app.yaml如果用 kubectl 命令的话 , 示例如下
kubectl kustomize services/demo-app/dev/ > demo-app.yaml最终结果
文章插图
文章插图
apiVersion: v1kind: Namespacemetadata: labels: app: demo-app name: demo---apiVersion: v1kind: ServiceAccountmetadata: labels: app: demo-app managed-by: Kustomize name: demo-app namespace: demo---apiVersion: v1data: config.json: |- { "SOME_CONFIG": "/demo/path" }kind: ConfigMapmetadata: labels: app: demo-app name: demo-app-config-t7c64mbtt2 namespace: demo---apiVersion: v1kind: Servicemetadata: labels: app: demo-app managed-by: Kustomize name: demo-app namespace: demospec: ports: - port: 8080 protocol: TCP targetPort: http selector: app: demo-app managed-by: Kustomize type: ClusterIP---apiVersion: apps/v1kind: Deploymentmetadata: labels: app: demo-app managed-by: Kustomize name: demo-app namespace: demospec: replicas: 1 selector: matchLabels: app: demo-app managed-by: Kustomize template: metadata: labels: app: demo-app managed-by: Kustomize spec: containers: - image: wadexu007/demo:1.0.0 imagePullPolicy: IfNotPresent livenessProbe: failureThreshold: 5 httpGet: path: /pizzas port: 8080 initialDelaySeconds: 10 periodSeconds: 40 timeoutSeconds: 1 name: app ports: - containerPort: 8080 name: http readinessProbe: failureThreshold: 5 httpGet: path: /pizzas port: 8080 initialDelaySeconds: 10 periodSeconds: 20 timeoutSeconds: 1 resources: limits: cpu: 1 memory: 1Gi requests: cpu: 200m memory: 256Mi securityContext: allowPrivilegeEscalation: false volumeMounts: - mountPath: /app/conf/config.json name: config-volume subPath: config.json serviceAccountName: demo-app volumes: - configMap: name: demo-app-config-t7c64mbtt2 name: config-volume
推荐阅读
- Windows下自动云备份思源笔记到Gitee
- 云原生之旅 - 5)Kubernetes时代的包管理工具 Helm
- 云顶之弈碧波法师阵容怎么玩
- 云上当空接龙规则(接龙规则口诀)
- 云上空当接龙怎么玩(空当接龙怎么玩教学说明)
- mqtt_simple例程 nrf9160做主控连接阿里云——
- 云顶之弈S7.5怒玉豹女阵容怎么玩
- 云顶之弈玉龙怎么换形锤阵容
- 云原生之旅 - 4)基础设施即代码 使用 Terraform 创建 Kubernetes
- Git 02: git管理码云代码仓库 + IDEA集成使用git