[英]COPY in Dockerfile works in docker but not in kubernetes
I am trying to deploy a simple HTML file to Kubernetes and host it using Nginx as a test.我正在尝试将一个简单的 HTML 文件部署到 Kubernetes 并使用 Nginx 作为测试来托管它。 I am running into issues when copying over my website files.
复制我的网站文件时遇到问题。
Dockerfile Dockerfile
FROM nginx:alpine
COPY ./public /usr/share/nginx/html/
When I build this image and run it using docker run
the website loads fine and I see my index.html file located in my public directory.当我构建这个图像并使用
docker run
它时,网站加载正常,我看到我的 index.html 文件位于我的公共目录中。 If I try to run this in a pod using kubectl
the files don't get copied over.如果我尝试使用
kubectl
在 pod 中运行它,则不会复制文件。 All I see when I go to my site is the default Nginx welcome page.当我 go 访问我的网站时,我看到的只是默认的 Nginx 欢迎页面。 I am not sure why this is the case.
我不确定为什么会这样。 the cluster is hosted on AWS EKS so it's remote to all the files.
该集群托管在 AWS EKS 上,因此它对所有文件都是远程的。 This is the same as I build and host my docker image on GitLab.
这与我在 GitLab 上构建和托管 docker 映像相同。
The image builds without any errors and as I said works fine when run in vanilla docker.图像构建没有任何错误,正如我所说,在 vanilla docker 中运行时工作正常。 It's only when I move over to Kubernetes that I run into issues.
只有当我转到 Kubernetes 时,我才会遇到问题。
I've made the project public so you guys can see all the abstractions that I might have left out in my question.我已经公开了这个项目,所以你们可以看到我可能在我的问题中遗漏的所有抽象。
https://gitlab.com/k8group/k8site https://gitlab.com/k8group/k8site
Any help is appreciated.任何帮助表示赞赏。
Best Regards, Eddy.最好的问候,埃迪。
I know if is only this, but in the quick glance I can say the key value in your ingress template must be pointing to the service port, not to the pod container port.我知道是否只是这个,但快速浏览一下,我可以说你的入口模板中的键值必须指向服务端口,而不是 pod 容器端口。 Check the right config below:
检查下面的正确配置:
kind: Service
apiVersion: v1
metadata:
name: k8site
spec:
selector:
app: k8site
ports:
- port: 8080
targetPort: 80
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/cache-enable: "false"
name: k8site-ingress
spec:
rules:
- host: prod.pepefanclub.com
http:
paths:
- backend:
serviceName: k8site
servicePort: 8080 <--- this must be the service port, that is 8080
So it looks like this was a case of the image not being pulled.所以看起来这是一个图像没有被拉出的情况。 I changed the commit tag from master to a hash and the site started working.
我将提交标签从 master 更改为 hash 并且该站点开始工作。
changing a variable in my ci pipeline from更改我的 ci 管道中的变量
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
to至
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
thanks, @EugeneDW for pointing me in the correct direction.谢谢,@EugeneDW 为我指明了正确的方向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.