Merge pull request #27220 from xordspar0/patch-1
Document using generators in Deployments
This commit is contained in:
@@ -114,6 +114,98 @@ metadata:
|
|||||||
name: example-configmap-2-g2hdhfc6tk
|
name: example-configmap-2-g2hdhfc6tk
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To use a generated ConfigMap in a Deployment, reference it by the name of the configMapGenerator. Kustomize will automatically replace this name with the generated name.
|
||||||
|
|
||||||
|
This is an example deployment that uses a generated ConfigMap:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# Create a application.properties file
|
||||||
|
cat <<EOF >application.properties
|
||||||
|
FOO=Bar
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat <<EOF >deployment.yaml
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: my-app
|
||||||
|
labels:
|
||||||
|
app: my-app
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: my-app
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: my-app
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: app
|
||||||
|
image: my-app
|
||||||
|
volumeMount:
|
||||||
|
- name: config
|
||||||
|
mountPath: /config
|
||||||
|
volumes:
|
||||||
|
- name: config
|
||||||
|
configMap:
|
||||||
|
name: example-configmap-1
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat <<EOF >./kustomization.yaml
|
||||||
|
resources:
|
||||||
|
- deployment.yaml
|
||||||
|
configMapGenerator:
|
||||||
|
- name: example-configmap-1
|
||||||
|
files:
|
||||||
|
- application.properties
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
Generate the ConfigMap and Deployment:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
kubectl kustomize ./
|
||||||
|
```
|
||||||
|
|
||||||
|
The generated Deployment will refer to the generated ConfigMap by name:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
application.properties: |
|
||||||
|
FOO=Bar
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: example-configmap-1-g4hk9g2ff8
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: my-app
|
||||||
|
name: my-app
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: my-app
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: my-app
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: my-app
|
||||||
|
name: app
|
||||||
|
volumeMount:
|
||||||
|
- mountPath: /config
|
||||||
|
name: config
|
||||||
|
volumes:
|
||||||
|
- configMap:
|
||||||
|
name: example-configmap-1-g4hk9g2ff8
|
||||||
|
name: config
|
||||||
|
```
|
||||||
|
|
||||||
#### secretGenerator
|
#### secretGenerator
|
||||||
|
|
||||||
You can generate Secrets from files or literal key-value pairs. To generate a Secret from a file, add an entry to the `files` list in `secretGenerator`. Here is an example of generating a Secret with a data item from a file:
|
You can generate Secrets from files or literal key-value pairs. To generate a Secret from a file, add an entry to the `files` list in `secretGenerator`. Here is an example of generating a Secret with a data item from a file:
|
||||||
@@ -170,6 +262,53 @@ metadata:
|
|||||||
type: Opaque
|
type: Opaque
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Like ConfigMaps, generated Secrets can be used in Deployments by refering to the name of the secretGenerator:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# Create a password.txt file
|
||||||
|
cat <<EOF >./password.txt
|
||||||
|
username=admin
|
||||||
|
password=secret
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat <<EOF >deployment.yaml
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: my-app
|
||||||
|
labels:
|
||||||
|
app: my-app
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: my-app
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: my-app
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: app
|
||||||
|
image: my-app
|
||||||
|
volumeMount:
|
||||||
|
- name: password
|
||||||
|
mountPath: /secrets
|
||||||
|
volumes:
|
||||||
|
- name: password
|
||||||
|
secret:
|
||||||
|
secretName: example-secret-1
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat <<EOF >./kustomization.yaml
|
||||||
|
resources:
|
||||||
|
- deployment.yaml
|
||||||
|
secretGenerator:
|
||||||
|
- name: example-secret-1
|
||||||
|
files:
|
||||||
|
- password.txt
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
#### generatorOptions
|
#### generatorOptions
|
||||||
|
|
||||||
The generated ConfigMaps and Secrets have a content hash suffix appended. This ensures that a new ConfigMap or Secret is generated when the contents are changed. To disable the behavior of appending a suffix, one can use `generatorOptions`. Besides that, it is also possible to specify cross-cutting options for generated ConfigMaps and Secrets.
|
The generated ConfigMaps and Secrets have a content hash suffix appended. This ensures that a new ConfigMap or Secret is generated when the contents are changed. To disable the behavior of appending a suffix, one can use `generatorOptions`. Besides that, it is also possible to specify cross-cutting options for generated ConfigMaps and Secrets.
|
||||||
|
|||||||
Reference in New Issue
Block a user