前提条件:
- K8S集群中正确部署了virtual-kubelet(serverless Kubernetes 默认集成)
ECI支持原生的ConfigMap,可以像原生K8S集群一样使用ConfigMap:
# kubectl create configmap demo --from-literal=test=configmap
configmap/demo created
# kubectl get configmap demo -o yaml
apiVersion: v1
data:
test: configmap
kind: ConfigMap
metadata:
creationTimestamp: "2020-01-20T12:54:42Z"
name: demo
namespace: default
resourceVersion: "15340926"
selfLink: /api/v1/namespaces/default/configmaps/demo
uid: 07119167-3b84-11ea-8c0c-4ac7cb9a7625
将以下内容保存为pod.yaml:
apiVersion: v1
kind: Pod
metadata:
name: test-configmap
spec:
# ACK场景下可以通过nodeName指定调度到ECI
# nodeName: virtual-node-eci-0
containers:
- name: nginx
image: nginx:latest
volumeMounts:
- name: config-volume
mountPath: /cache-test
volumes:
- name: config-volume
configMap:
name: demo
items:
- key: test
path: keys
restartPolicy: Always
使用kubectl创建ECI实例:
# kubectl create -f pod.yaml
pod/test-configmap created
# kubectl get pod test-configmap
NAME READY STATUS RESTARTS AGE
test-configmap 1/1 Running 0 57s
# kubectl exec -it test-configmap bash
root@test-configmap:/# ls cache-test/
keys
root@test-configmap:/# cat cache-test/keys
configmap
可见,已经将ConfigMap中的配置项挂载到了容器内。