Prerequisites:
- The virtual-kubelet node is deployed in the target Kubernetes cluster. Note that a serverless Kubernetes cluster is embedded with the virtual-kubelet node.
Elastic Container Instance (ECI) provides native support for ConfigMaps. You can use a ConfigMap in an ECI in the same way as that in native Kubernetes.
# 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
Save the following sample code in a YAML file named pod.yaml:
apiVersion: v1
kind: Pod
metadata:
name: test-configmap
spec:
nodeName: virtual-kubelet
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
Use the kubectl client to create an ECI based on the preceding configuration file.
# 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
According to the command output, the ConfigMap is mounted to the ECI as a volume.