带有AspNet Core Web API的容器在Docker上运行,但不在AKS Kubernetes上运行



我有一个 ASP.Net 核心Web API 2.2项目,可以在我的本地Docker桌面上正常运行。我正在尝试在 Azure 的 AKS 上运行它,但它不会在那里运行,我不明白为什么。
下面是我的 PowerShell 脚本,我使用它将项目发布到稍后将插入到容器中的app目录中:

Remove-Item ........projectsMyProject.Selenium.CommomsrcSelenium.APIbinRelease* -Force -Recurse
dotnet publish ........projectsMyProject.Selenium.CommomsrcSelenium.Comum.sln -c Release -r linux-musl-x64
$path = (Get-Location).ToString() + "app"
if (Test-Path($path))
{
Remove-Item -Path $path -Force -Recurse
}
New-Item -ItemType Directory -Force app
Get-ChildItem ........projectsMyProject.Selenium.CommomsrcSelenium.APIbinReleasenetcoreapp2.2linux-musl-x64publish* | Copy-Item -Destination .app -Recurse

这是我的Dockerfile

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/runtime:2.2-alpine3.9
WORKDIR /app /app
WORKDIR /app
ENTRYPOINT ["dotnet", "Selenium.API.dll"]

下面是我的 Docker 构建命令:

docker build -t mylocaldocker/selenium-web-app:latest -t mylocaldocker/selenium-web-app:v0.0.2 .

和我的 Docker 运行命令

docker run --name selweb --detach --rm -p 85:80 mylocaldocker/selenium-web-app:latest

一切都旋转得很好,很顺利,我可以在端口 85 上本地发送请求而不会出现问题(IIS 正在使用端口 80)
但是,在 Azure 的 AKS 上执行类似的过程,容器不会启动。我使用相同的PowerShell脚本来发布我的应用程序,并且dockerfile也是相同的。我的生成命令发生了变化,以便我可以推送到 Azure 的 Docker 注册表:

docker build -t myproject.azurecr.io/selenium-web-app:latest -t myproject.azurecr.io/selenium-web-app:v0.0.1 .

我登录到 Azure Docker 注册表,并将映像推送到其中:

docker push myproject.azurecr.io/selenium-web-app:latest

我已创建 AKS 群集,并授予从注册表拉取映像的权限。我尝试使用以下命令在 AKS 上运行映像:

kubectl run seleniumweb --image myproject.azurecr.io/selenium-web-app:latest --port 80

我得到了回应

deployment.apps "seleniumweb" created

但是,当我得到正在运行的 pod 时:

kubectl get pods

我的容器上出现错误状态

NAME                           READY     STATUS    RESTARTS   AGE
seleniumweb-7b5f645698-9g7f6   0/1       Error     4          1m

当我从 pod 获取日志时:

kubectl logs seleniumweb-7b5f645698-9g7f6

我得到这个:

Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409

下面是 kubectl 对 pod 的描述结果:

kubectl describe pods
Name:               seleniumweb-7b5f645698-9g7f6
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               aks-agentpool-41564776-0/10.240.0.4
Start Time:         Sun, 02 Jun 2019 11:40:47 -0300
Labels:             pod-template-hash=7b5f645698
run=seleniumweb
Annotations:        <none>
Status:             Running
IP:                 10.240.0.25
Controlled By:      ReplicaSet/seleniumweb-7b5f645698
Containers:
seleniumweb:
Container ID:   docker://1d548f4934632efb0b7c5a59dd0ac2bd173f2ee8fa5196b45d480fb10e88a536
Image:          myproject.azurecr.io/selenium-web-app:latest
Image ID:       docker-pullable://myproject.azurecr.io/selenium-web-app@sha256:97e2915a8b43aa8e726799b76274bb9b5b852cb6c78a8630005997e310cfd41a
Port:           80/TCP
Host Port:      0/TCP
State:          Waiting
Reason:       CrashLoopBackOff
Last State:     Terminated
Reason:       Error
Exit Code:    145
Started:      Sun, 02 Jun 2019 11:43:39 -0300
Finished:     Sun, 02 Jun 2019 11:43:39 -0300
Ready:          False
Restart Count:  5
Environment:
KUBERNETES_PORT_443_TCP_ADDR:  myprojectus-dns-54302b78.hcp.eastus2.azmk8s.io
KUBERNETES_PORT:               tcp://myprojectus-dns-54302b78.hcp.eastus2.azmk8s.io:443
KUBERNETES_PORT_443_TCP:       tcp://myprojectus-dns-54302b78.hcp.eastus2.azmk8s.io:443
KUBERNETES_SERVICE_HOST:       myprojectus-dns-54302b78.hcp.eastus2.azmk8s.io
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-mhvfv (ro)
Conditions:
Type              Status
Initialized       True
Ready             False
ContainersReady   False
PodScheduled      True
Volumes:
default-token-mhvfv:
Type:        Secret (a volume populated by a Secret)
SecretName:  default-token-mhvfv
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  5m                 default-scheduler                  Successfully assigned default/seleniumweb-7b5f645698-9g7f6 to aks-agentpool-41564776-0
Normal   Created    4m (x4 over 5m)    kubelet, aks-agentpool-41564776-0  Created container
Normal   Started    4m (x4 over 5m)    kubelet, aks-agentpool-41564776-0  Started container
Normal   Pulling    3m (x5 over 5m)    kubelet, aks-agentpool-41564776-0  pulling image "myproject.azurecr.io/selenium-web-app:latest"
Normal   Pulled     3m (x5 over 5m)    kubelet, aks-agentpool-41564776-0  Successfully pulled image "myproject.azurecr.io/selenium-web-app:latest"
Warning  BackOff    20s (x24 over 5m)  kubelet, aks-agentpool-41564776-0  Back-off restarting failed container

我不明白为什么,因为我的本地 Docker 一切运行良好。任何帮助将不胜感激。谢谢

Dockerfile看起来很有趣。 它什么都不做。 WORKDIR 只是"为 Dockerfile 中遵循它的任何 RUN、CMD、ENTRYPOINT、COPY 和 ADD 指令设置工作目录"(来自 docs.docker.com)。 因此,您将工作目录设置两次,然后仅此而已。 然后,入口点将指向一个不存在的.dll,因为您从未复制过它。 我想你想删除第一个 WORKDIR 命令,并在剩下的 WORKDIR 命令之后添加它:

COPY . ./

更好的是,使用两阶段构建,使其在 docker 上构建,然后将构建复制到发布的运行时映像。

我不知道为什么 docker 运行在本地为您工作。 它是否以某种方式拾起了旧图像? 根据您的 Dockerfile,它不应该运行。

相关内容

最新更新