我正在尝试在 Minikube 中运行 docker 容器注册表以测试我正在编写的 CSI 驱动程序。

我在 mac 上运行 minikube 并尝试使用以下 minikube start 命令: minikube start --vm-driver=hyperkit --disk-size=40g 。我已经尝试过 kubeadm 和 localkube bootstrap 以及 virtualbox vm-driver。

这是我用于 registry pod 部署的资源定义。

---
apiVersion: v1
kind: Pod
metadata:
  name: registry
  labels:
    app: registry
  namespace: docker-registry
spec:
  containers:
  - name: registry
    image: registry:2
    imagePullPolicy: Always
    ports:
      - containerPort: 5000
    volumeMounts:
      - mountPath: /var/lib/registry
        name: registry-data
  volumes:
  - hostPath:
      path: /var/lib/kubelet/plugins/csi-registry
      type: DirectoryOrCreate
    name: registry-data

我尝试使用 kubectl apply -f registry-setup.yaml 创建它。在运行之前,我的 minikube 集群报告自己已准备就绪,所有正常的 minikube 容器都在运行。

但是,这无法运行,并且在运行 kubectl describe pod 时,我看到以下消息:
    Name:         registry
    Namespace:    docker-registry
    Node:         minikube/192.168.64.43
    Start Time:   Wed, 08 Aug 2018 12:24:27 -0700
    Labels:       app=registry
    Annotations:  kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"labels":{"app":"registry"},"name":"registry","namespace":"docker-registry"},"spec":{"cont...
    Status:       Running
    IP:           172.17.0.2
    Containers:
    registry:
        Container ID:   docker://42e5193ac563c2b2e2a2b381c91350d30f7e7c5009a30a5977d33b403a374e7f
        Image:          registry:2
    ...
    TRUNCATED FOR SPACE
    ...
    Events:
    Type    Reason                 Age   From               Message
    ----    ------                 ----  ----               -------
    Normal  Scheduled              1m    default-scheduler  Successfully assigned registry to minikube
    Normal  SuccessfulMountVolume  1m    kubelet, minikube  MountVolume.SetUp succeeded for volume "registry-data"
    Normal  SuccessfulMountVolume  1m    kubelet, minikube  MountVolume.SetUp succeeded for volume "default-token-kq5mq"
    Normal  Pulling                1m    kubelet, minikube  pulling image "registry:2"
    Normal  Pulled                 1m    kubelet, minikube  Successfully pulled image "registry:2"
    Normal  Created                1m    kubelet, minikube  Created container
    Normal  Started                1m    kubelet, minikube  Started container
    ...
    TRUNCATED
    ...
    Name:         storage-provisioner
    Namespace:    kube-system
    Node:         minikube/192.168.64.43
    Start Time:   Wed, 08 Aug 2018 12:24:38 -0700
    Labels:       addonmanager.kubernetes.io/mode=Reconcile
                integration-test=storage-provisioner
    Annotations:  kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"labels":{"addonmanager.kubernetes.io/mode":"Reconcile","integration-test":"storage-provis...
    Status:       Pending
    IP:           192.168.64.43
    Containers:
    storage-provisioner:
        Container ID:
        Image:         gcr.io/k8s-minikube/storage-provisioner:v1.8.1
        Image ID:
        Port:          <none>
        Host Port:     <none>
        Command:
        /storage-provisioner
        State:          Waiting
        Reason:       ErrImagePull
        Ready:          False
        Restart Count:  0
        Environment:    <none>
        Mounts:
        /tmp from tmp (rw)
        /var/run/secrets/kubernetes.io/serviceaccount from storage-provisioner-token-sb5hz (ro)
    Conditions:
    Type           Status
    Initialized    True
    Ready          False
    PodScheduled   True
    Volumes:
    tmp:
        Type:          HostPath (bare host directory volume)
        Path:          /tmp
        HostPathType:  Directory
    storage-provisioner-token-sb5hz:
        Type:        Secret (a volume populated by a Secret)
        SecretName:  storage-provisioner-token-sb5hz
        Optional:    false
    QoS Class:       BestEffort
    Node-Selectors:  <none>
    Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                    node.kubernetes.io/unreachable:NoExecute for 300s
    Events:
    Type     Reason                 Age               From               Message
    ----     ------                 ----              ----               -------
    Normal   Scheduled              1m                default-scheduler  Successfully assigned storage-provisioner to minikube
    Normal   SuccessfulMountVolume  1m                kubelet, minikube  MountVolume.SetUp succeeded for volume "tmp"
    Normal   SuccessfulMountVolume  1m                kubelet, minikube  MountVolume.SetUp succeeded for volume "storage-provisioner-token-sb5hz"
    Normal   Pulling                23s (x3 over 1m)  kubelet, minikube  pulling image "gcr.io/k8s-minikube/storage-provisioner:v1.8.1"
    Warning  Failed                 21s (x3 over 1m)  kubelet, minikube  Failed to pull image "gcr.io/k8s-minikube/storage-provisioner:v1.8.1": rpc error: code = Unknown desc = failed to register layer: Error processing tar file(exit status 1): write /storage-provisioner: no space left on device
    Warning  Failed                 21s (x3 over 1m)  kubelet, minikube  Error: ErrImagePull
    Normal   BackOff                7s (x3 over 1m)   kubelet, minikube  Back-off pulling image "gcr.io/k8s-minikube/storage-provisioner:v1.8.1"
    Warning  Failed                 7s (x3 over 1m)   kubelet, minikube  Error: ImagePullBackOff
    ------------------------------------------------------------
    ...

因此,当注册表容器正确启动时,一些其他 minikube 服务(包括 dns、http 入口服务等)开始失败,原因如下: write /storage-provisioner: no space left on device 。尽管为 minikube 分配了 40GB 的磁盘大小,但似乎 minikube 正在尝试写入只有 1GB 空间的 rootfsdevtempfs(取决于 vm-driver)。
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          919M  713M  206M  78% /
devtmpfs        919M     0  919M   0% /dev
tmpfs           996M     0  996M   0% /dev/shm
tmpfs           996M  8.9M  987M   1% /run
tmpfs           996M     0  996M   0% /sys/fs/cgroup
tmpfs           996M  8.0K  996M   1% /tmp
/dev/sda1        34G  1.3G   30G   4% /mnt/sda1

有没有办法让 minikube 在拉取镜像和创建容器时实际使用分配给/mnt/sda1 而不是 rootfs 的 34GB 空间?

在此先感谢您的帮助!

最佳答案

您需要配置 Minikube 虚拟机以使用 /dev/sda1 而不是 / for Docker。要登录它,请使用 minikube ssh 命令。

比你有两个选择:

  • /dev/sda1 挂载到 var/lib/docker ,但不要忘记在此之前将原始 var/lib/docker 的内容复制到 /mnt/sda1
  • 重新配置 Docker 以使用 /mnt/sda1 而不是 var/lib/docker 来存储图像。查看此 link 以获取有关它的更多信息。
  • 关于kubernetes - 尽管 --disk-size 标志,Minikube 空间不足并失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51755703/

    10-15 22:15