【问题标题】:How to run a local docker image as a k3s node如何将本地 docker 镜像作为 k3s 节点运行
【发布时间】:2021-11-06 01:52:05
【问题描述】:

我刚开始使用 docker 和 k3s。

我有一个本地 docker 镜像,里面有一个自定义应用程序。

我想知道如何将它设置为 k3s 上的 pod。

我使用 docker 而不是 containerd 设置了 k3s,但是当我运行 kubectl create 时,我仍然收到错误 ImagePullBackOff。

有人可以帮忙吗?谢谢!

【问题讨论】:

  • 你能告诉我们关于图像拉回退的错误吗?

标签: docker kubectl k3s


【解决方案1】:

这是我过去为公司演示编写的演示说明:

参考文献

安装/设置

sudo snap install microk8s --classic --channel=1.21  

sudo usermod -a -G microk8s $USER 
sudo chown -f -R $USER ~/.kube 
su - $USER 

# DNS setup

microk8s.kubectl run -i --tty --image busybox:1.28.4 dns-test --restart=Never --rm /bin/sh 

microk8s 启用注册表 dns 存储

开始

sudo systemctl start docker 
microk8s start 

服务检查

microk8s status --wait-ready 

microk8s kubectl get nodes 
microk8s kubectl get services 

应用部署


# Pull hello world image from docker hub

docker pull hello-world 

# Push hello world image to microk8s registry

docker tag hello-world localhost:32000/hello-world 
docker push localhost:32000/hello-world 

# Try it

docker run --rm localhost:32000/hello-world 

应用运行

microk8s kubectl run my-demo --image localhost:32000/hello-world 
microk8s kubectl expose pod my-demo --port 8080 --target-port 8080 

终止

microk8s kubectl delete service my-demo 
microk8s kubectl delete pod my-demo 

# or  

kubectl delete -f app.yaml 

# then 

microk8s.stop 

【讨论】:

  • 我通过推送 dockerimage 并成功检索它做了类似的事情。但是,当我运行 kubectl run 时,它仍然无法获得返回 ErrImagePull 和 ImagePullBackOff 的图像
  • 不幸的是,我不知道这是您的环境问题,但我的演示对我有用。
【解决方案2】:

我能够通过恢复到 containerd 并遵循本指南来使其工作:https://cwienczek.com/2020/06/import-images-to-k3s-without-docker-registry/ 我现在正在创建 yaml 文件并使用 ctr 上传 dockerimages。

【讨论】:

    猜你喜欢
    • 2019-12-26
    • 2023-01-30
    • 2020-01-06
    • 2022-10-15
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多