k8s configmap secret
时间: 2023-08-20 20:08:36 浏览: 102
K8S入门基础课件docx版本
Kubernetes (k8s) provides two types of resources for managing configuration data: ConfigMaps and Secrets.
ConfigMaps are used to store non-sensitive configuration data, such as environment variables, command-line arguments, or configuration files. They can be created from literal values, directories, or files.
On the other hand, Secrets are used to store sensitive information, such as usernames, passwords, or API keys. They are base64-encoded and can be mounted as files or used as environment variables in pods.
To create a ConfigMap, you can use the `kubectl create configmap` command and provide the data using flags or a configuration file. For example:
```bash
kubectl create configmap my-config --from-literal=key1=value1 --from-file=path/to/file
```
To create a Secret, you can use the `kubectl create secret` command and provide the sensitive data using flags or a configuration file. For example:
```bash
kubectl create secret generic my-secret --from-literal=username=admin --from-file=path/to/file
```
Both ConfigMaps and Secrets can be mounted as volumes or used as environment variables in pods. You can reference them in the pod's YAML file using the `env` or `volumes` sections.
I hope this helps! Let me know if you have any more questions.
阅读全文