如果您想以不同的配置运行 4 个不同的 Pod,您必须在 kubernetes 中部署 4 个不同的部署。
您可以根据需要创建不同的 configmap
,存储整个 Application.yaml
文件或环境变量,并将其注入不同部署。
如何将整个 application.yaml
存储在 config map
中
apiVersion: v1
kind: ConfigMap
metadata:
name: yaml-region-first
data:
application.yaml: |-
data: test,region: first-region
与您可以使用第二个部署创建配置映射的方式相同。
apiVersion: v1
kind: ConfigMap
metadata:
name: yaml-region-second
data:
application.yaml: |-
data: test,region: second-region
您可以将此 configmap
注入到每个部署中
示例:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: hello-app
name: hello-app
namespace: default
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: hello-app
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: hello-app
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /etc/nginx/app.yaml
name: yaml-file
readOnly: true
volumes:
- configMap:
name: yaml-region-second
optional: false
name: yaml-file
相应地,您也可以创建舵图。
如果您只是传递单个环境而不是将整个文件存储在 configmap
中,您可以直接为部署添加价值。
示例:
apiVersion: v1
kind: Pod
metadata:
name: print-greeting
spec:
containers:
- name: env-print-demo
image: bash
env:
- name: REGION
value: "one"
- name: HONORIFIC
value: "The Most Honorable"
- name: NAME
value: "Kubernetes"
command: ["echo"]
args: ["$(GREETING) $(HONORIFIC) $(NAME)"]
https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/
对于每个部署,您的环境都会有所不同,并且在掌舵中,您可以使用 CLI 命令dynamically
或 update
它。
本文链接:https://www.f2er.com/930.html