应用程序未使用 Kubernetes 正确部署
Application not properly deployed using Kuberenetes
我开发了一个 Spring 引导应用程序,我使用 docker-compose 来创建我的容器。对于 Kubernetes,我通过 minikubes 使用了 kompose。我将图像推送到 docker hub,并尝试用两种方式部署我的容器
kompose up
和
kompose convert -f docker-compose.yaml
kubectl create -f (deplymentfiles)
但是我收到了这个回复
WARN Volume mount on the host "/home/App/src/main/docker/postgres-data" isn't supported - ignoring path on the host
INFO We are going to create Kubernetes Deployments, Services and PersistentVolumeClaims for your Dockerized application. If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead.
INFO Deploying application in "default" namespace
INFO Successfully created Service: adminer
INFO Successfully created Service: app
INFO Successfully created Service: mypostgres
INFO Successfully created Deployment: adminer
INFO Successfully created Deployment: app
INFO Successfully created Deployment: mypostgres
INFO Successfully created PersistentVolumeClaim: mypostgres-claim0 of size 100Mi. If your cluster has dynamic storage provisioning, you don't have to do anything. Otherwise you have to create PersistentVolume to make PVC work
当我运行kubectl get pods
NAME READY STATUS RESTARTS AGE
adminer-6cd96f8846-69qb8 1/1 Running 0 2m
app-5796c489ff-m46xk 0/1 ImagePullBackOff 0 2m
mypostgres-649865b4d8-nhglj 1/1 Running 0 2m
kubectl describe pod app-5796c489ff-m46xk
显示这个
Name: app-5796c489ff-m46xk
Namespace: default
Node: minikube/192.168.99.100
Start Time: Mon, 11 Jun 2018 11:02:32 +0200
Labels: io.kompose.service=app
pod-template-hash=1352704599
Annotations: <none>
Status: Pending
IP: 172.17.0.3
Controlled By: ReplicaSet/app-5796c489ff
Containers:
app:
Container ID:
Image: iroolapp
Image ID:
Port: 8086/TCP
Host Port: 0/TCP
State: Waiting
Reason: ImagePullBackOff
Ready: False
Restart Count: 0
Environment:
DATABASE_HOST: mypostgres
DATABASE_NAME: test
DATABASE_PASSWORD: root
DATABASE_PORT: 5432
DATABASE_USER: root
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-wdb8n (ro)
Conditions:
Type Status
Initialized True
Ready False
PodScheduled True
Volumes:
default-token-wdb8n:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-wdb8n
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 3m default-scheduler Successfully assigned app-5796c489ff-m46xk to minikube
Normal SuccessfulMountVolume 3m kubelet, minikube MountVolume.SetUp succeeded for volume "default-token-wdb8n"
Normal Pulling 1m (x4 over 3m) kubelet, minikube pulling image "iroolapp"
Warning Failed 1m (x4 over 3m) kubelet, minikube Failed to pull image "iroolapp": rpc error: code = Unknown desc = Error response from daemon: pull access denied for iroolapp, repository does not exist or may require 'docker login'
Warning Failed 1m (x4 over 3m) kubelet, minikube Error: ErrImagePull
Normal BackOff 1m (x6 over 3m) kubelet, minikube Back-off pulling image "iroolapp"
Warning Failed 1m (x6 over 3m) kubelet, minikube Error: ImagePullBackOff
最后这是我的 docker-compose 文件
version: '3'
services:
app:
image: iroolapp
depends_on:
- mypostgres
ports:
- "9000:8086"
environment:
- DATABASE_HOST=mypostgres
- DATABASE_USER=root
- DATABASE_PASSWORD=root
- DATABASE_NAME=test
- DATABASE_PORT=5432
networks:
default:
mypostgres:
image: postgres:9.6-alpine
container_name: mypostgres
ports:
- "5433:5432"
environment:
- POSTGRES_PASSWORD=root
- POSTGRES_USER=root
- POSTGRES_DB=irooldb
volumes:
- ./postgres-data:/var/lib/postgresql/data
adminer:
image: adminer
ports:
- 8080:8080
networks:
default:
networks:
default:
external:
name: mynetwork
我的问题是:ImagePullBackoff指的是什么?使用 kompose 是一个好方法吗?在使用 kubernetes
之前将图像推送到 docker hub 是必要的步骤吗
Q1
what does ImagePullBackoff refers to
从日志中可以看到多次尝试拉取镜像"iroolapp" pod app-5796c489ff-m46xk的容器需求(参见pod的container
字段image
)从注册表和所有失败。 ImagePullBackoff
发生在这些失败之后。
Q2
using kompose is it a good approach?
没用过...
Q3
and is it a necessary step to push images to docker hub before using kubernetes
不是。如果只是为了简单测试,您可以通过将 imagePullPolicy
设置为 IfNotPreset
或 Never
来使用本地图像(确保图像已加载)。或者,您可以拥有自己的私人注册表。
ImagePullBackoff
表示无法获取图片
你真的看过错误信息了吗?它说 Failed to pull image "iroolapp": rpc error: code = Unknown desc = Error response from daemon: pull access denied for iroolapp, repository does not exist or may require 'docker login'
您是否登录 docker 中心? docker 中心里有你的图片吗?因为那是它试图拉取图像的地方。
我想通了,事实上,在我的 docker-compose 文件中,我应该指定图像引用在 docker 中心推送的存储库中发布的图像:
image: docker.io/<dockerHub username>/<imagename>
我认为图像名称根本没有得到正确的方向。如果您存储在您的回购协议中,请提供完整路径,如 "username/repo:tag" 或首先在终端 "docker search imagename" 中通过命令搜索。
Kubernetes 一次又一次地拉取图像直到 运行 条件,所以可能是 RESTART 计数变高了。所以给它正确的 url 或私人回购路径。
我开发了一个 Spring 引导应用程序,我使用 docker-compose 来创建我的容器。对于 Kubernetes,我通过 minikubes 使用了 kompose。我将图像推送到 docker hub,并尝试用两种方式部署我的容器
kompose up
和
kompose convert -f docker-compose.yaml kubectl create -f (deplymentfiles)
但是我收到了这个回复
WARN Volume mount on the host "/home/App/src/main/docker/postgres-data" isn't supported - ignoring path on the host
INFO We are going to create Kubernetes Deployments, Services and PersistentVolumeClaims for your Dockerized application. If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead.
INFO Deploying application in "default" namespace
INFO Successfully created Service: adminer
INFO Successfully created Service: app
INFO Successfully created Service: mypostgres
INFO Successfully created Deployment: adminer
INFO Successfully created Deployment: app
INFO Successfully created Deployment: mypostgres
INFO Successfully created PersistentVolumeClaim: mypostgres-claim0 of size 100Mi. If your cluster has dynamic storage provisioning, you don't have to do anything. Otherwise you have to create PersistentVolume to make PVC work
当我运行kubectl get pods
NAME READY STATUS RESTARTS AGE
adminer-6cd96f8846-69qb8 1/1 Running 0 2m
app-5796c489ff-m46xk 0/1 ImagePullBackOff 0 2m
mypostgres-649865b4d8-nhglj 1/1 Running 0 2m
kubectl describe pod app-5796c489ff-m46xk
显示这个
Name: app-5796c489ff-m46xk
Namespace: default
Node: minikube/192.168.99.100
Start Time: Mon, 11 Jun 2018 11:02:32 +0200
Labels: io.kompose.service=app
pod-template-hash=1352704599
Annotations: <none>
Status: Pending
IP: 172.17.0.3
Controlled By: ReplicaSet/app-5796c489ff
Containers:
app:
Container ID:
Image: iroolapp
Image ID:
Port: 8086/TCP
Host Port: 0/TCP
State: Waiting
Reason: ImagePullBackOff
Ready: False
Restart Count: 0
Environment:
DATABASE_HOST: mypostgres
DATABASE_NAME: test
DATABASE_PASSWORD: root
DATABASE_PORT: 5432
DATABASE_USER: root
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-wdb8n (ro)
Conditions:
Type Status
Initialized True
Ready False
PodScheduled True
Volumes:
default-token-wdb8n:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-wdb8n
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 3m default-scheduler Successfully assigned app-5796c489ff-m46xk to minikube
Normal SuccessfulMountVolume 3m kubelet, minikube MountVolume.SetUp succeeded for volume "default-token-wdb8n"
Normal Pulling 1m (x4 over 3m) kubelet, minikube pulling image "iroolapp"
Warning Failed 1m (x4 over 3m) kubelet, minikube Failed to pull image "iroolapp": rpc error: code = Unknown desc = Error response from daemon: pull access denied for iroolapp, repository does not exist or may require 'docker login'
Warning Failed 1m (x4 over 3m) kubelet, minikube Error: ErrImagePull
Normal BackOff 1m (x6 over 3m) kubelet, minikube Back-off pulling image "iroolapp"
Warning Failed 1m (x6 over 3m) kubelet, minikube Error: ImagePullBackOff
最后这是我的 docker-compose 文件
version: '3'
services:
app:
image: iroolapp
depends_on:
- mypostgres
ports:
- "9000:8086"
environment:
- DATABASE_HOST=mypostgres
- DATABASE_USER=root
- DATABASE_PASSWORD=root
- DATABASE_NAME=test
- DATABASE_PORT=5432
networks:
default:
mypostgres:
image: postgres:9.6-alpine
container_name: mypostgres
ports:
- "5433:5432"
environment:
- POSTGRES_PASSWORD=root
- POSTGRES_USER=root
- POSTGRES_DB=irooldb
volumes:
- ./postgres-data:/var/lib/postgresql/data
adminer:
image: adminer
ports:
- 8080:8080
networks:
default:
networks:
default:
external:
name: mynetwork
我的问题是:ImagePullBackoff指的是什么?使用 kompose 是一个好方法吗?在使用 kubernetes
之前将图像推送到 docker hub 是必要的步骤吗Q1
what does ImagePullBackoff refers to
从日志中可以看到多次尝试拉取镜像"iroolapp" pod app-5796c489ff-m46xk的容器需求(参见pod的container
字段image
)从注册表和所有失败。 ImagePullBackoff
发生在这些失败之后。
Q2
using kompose is it a good approach?
没用过...
Q3
and is it a necessary step to push images to docker hub before using kubernetes
不是。如果只是为了简单测试,您可以通过将 imagePullPolicy
设置为 IfNotPreset
或 Never
来使用本地图像(确保图像已加载)。或者,您可以拥有自己的私人注册表。
ImagePullBackoff
表示无法获取图片
你真的看过错误信息了吗?它说 Failed to pull image "iroolapp": rpc error: code = Unknown desc = Error response from daemon: pull access denied for iroolapp, repository does not exist or may require 'docker login'
您是否登录 docker 中心? docker 中心里有你的图片吗?因为那是它试图拉取图像的地方。
我想通了,事实上,在我的 docker-compose 文件中,我应该指定图像引用在 docker 中心推送的存储库中发布的图像:
image: docker.io/<dockerHub username>/<imagename>
我认为图像名称根本没有得到正确的方向。如果您存储在您的回购协议中,请提供完整路径,如 "username/repo:tag" 或首先在终端 "docker search imagename" 中通过命令搜索。 Kubernetes 一次又一次地拉取图像直到 运行 条件,所以可能是 RESTART 计数变高了。所以给它正确的 url 或私人回购路径。