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 emptyDir volumes. You can use an emptyDir volume in an ECI in the same way as that in native Kubernetes. Save the following sample code in a YAML file named empty_dir.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  nodeName: virtual-kubelet
  containers:
  - image: nginx:latest
    name: test-container
    volumeMounts:
    - mountPath: /cache-test
      name: cache-volume
  volumes:
  - name: cache-volume
    emptyDir: {}

Use the kubectl client to create an ECI based on the preceding configuration file.

# kubectl create -f empty_dir.yaml
pod/test-pd created
# kubectl get pods
NAME         READY   STATUS    RESTARTS   AGE
test-pd      1/1     Running   0          61s
# kubectl exec -it test-pd bash
root@default-test-pd:/# ls
bin  boot  cache-test  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var