I am trying to deploy a simple HTML file to Kubernetes and host it using Nginx as a test. I am running into issues when copying over my website files.
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. If I try to run this in a pod using kubectl
the files don't get copied over. All I see when I go to my site is the default Nginx welcome page. I am not sure why this is the case. the cluster is hosted on AWS EKS so it's remote to all the files. This is the same as I build and host my docker image on GitLab.
The image builds without any errors and as I said works fine when run in vanilla docker. It's only when I move over to Kubernetes that I run into issues.
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
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. 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.
changing a variable in my ci pipeline from
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.