Kubernetes - 6.1 Config and Storage - ConfigMap
什么是ConfigMap
ConfigMap为Pod中的容器提供了配置文件、环境变量等非敏感信息,通过ConfigMap可以将Pod和其他组件分开,这将使得Pod更加有移植性,使得配置更加容器更改及管理,也使得Pod更加规范。
Config基本操作
通过kubectl create configmapkubectl create configmap nginx-configmap --from-literal=password=123456
通过yaml资源配置清单kubectl apply -f nginx-configmap.yaml
apiVersion: v1 kind: List metadata: items: - apiVersion: v1 data: password: "123456" kind: ConfigMap metadata: name: nginx-configmap
通过kubectl get configmap
查看详细信息
通过kubectl describe configmap
查看详细信息
ConfigMap作为存储卷被Pod调用
创建ConfigMapkubectl create configmap database-config --from-literal=user=root --from-literal=password=123456
通过YAML资源定义清单创建Pod并绑定ConfigMap为存储卷kubectl apply -f nginx-pod-configmap-volume.yaml
apiVersion: v1 kind: Pod metadata: name: nginx-pod spec: containers: - name: nginx image: nginx:1.16 volumeMounts: - name: config-volume mountPath: /etc/config volumes: - name: config-volume configMap: name: database-config
查看Pod容器挂载的ConfigMap存储卷kubectl exec -it nginx-pod /bin/bash
查看Pod详细信息,挂载了ConfigMap类型的Volumeskubectl describe pod nginx-pod
ConfigMap作为环境变量被Pod调用
kubectl create configmap database-config --from-literal=user=root --from-literal=password=123456
kubectl create configmap env-config --from-literal=LOG_LEVEL=ERROR
kubectl apply -f nginx-pod-configmap-env.yaml
apiVersion: v1 kind: Pod metadata: name: nginx-pod spec: containers: - name: nginx image: nginx:1.16 env: - name: DB_USER_CONFIG valueFrom: configMapKeyRef: name: database-config key: user - name: DB_PASSWORD_CONFIG valueFrom: configMapKeyRef: name: database-config key: password envFrom: - configMapRef: name: env-config
查看Pod容器的环境变量kubectl exec -it nginx-pod /bin/bash
查看Pod容器详细信息kubectl describe pod nginx-pod
Config注意的事项
- ConfigMap文件大小限制: 1MB (etcd的限制)
- ConfigMap必须在Pod引用它之前创建

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Kubernetes - 5.2 Discovery and Load Balancing - Ingress
什么是Ingress Ingress可以将Kubernetes内部的Service通过HTTP/HTTPS的虚拟主机方式暴露到集群外部,可以由Ingress定义请求的路由规则。 Ingress 基础操作 通过资源定义清单创建Ingresskubectl apply -f nginx-ingress.yaml apiVersion: extensions/v1beta1 kind: Ingress metadata: name: nginx-ingress spec: rules: - host: nginx.com http: paths: - backend: serviceName: nginx-service servicePort: 80 path: / tls: - hosts: - nginx.com secretName: ingress-certificate 查看ingress详细信息kubectl get ingress -o yaml kubectl describe ingress nginx-ingress Ingress开启TLS支持 在创建Ingress可...
- 下一篇
Kubernetes - 6.2 Config and Storage - Secrets
什么是Secret 通过Secret可以将敏感信息注入到Pod中的容器,一般用于存储访问私有仓库的账号密码、TLS证书、Token等。Secret可以做为容器依附在Pod中使用,或者可以通过环境变量引入。这是比直接使用ConfigMap更加安全的方式,降低敏感数据直接暴露给未授权用户的风险。 Secret 基本操作 通过kubectl create secret kubectl create secret generic nginx-secret --from-literal=password=123456 通过yaml资源配置清单先转换为Base64编码echo -n "123456" |base64 输出 MTIzNDU2kubectl apply -f nginx-secret.yaml apiVersion: v1 kind: Secret metadata: name: nginx-secret type: Opaque data: password: MTIzNDU2 Secret 类型 generic 从文件、目录或命令行参数中创建Secret。docker-regist...
相关文章
文章评论
共有0条评论来说两句吧...