I have a simple Hello World app on Dockerhub and I'm trying to run it in Kubernetes but no luck, nothing shows up.
Dockerfile:
FROM centos:7
RUN yum install httpd -y
RUN echo "Hello World" > /var/www/html/index.html
RUN chown -R apache:apache /var/www/html
EXPOSE 80
CMD [ "/usr/sbin/httpd", "-D", "FOREGROUND" ]
Kubernetes YAML:
apiVersion: apps/v1
kind: Deployment
metadata:
name: ingress-test
labels:
app: hello-world
spec:
replicas: 1
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: helloworld
image: 56789/world:v1
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: hello-world
spec:
selector:
app: hello-world
ports:
- protocol: "TCP"
port: 80
targetPort: 80
type: LoadBalancer
As you are running a simple hello world app, I assume you might use minikube & you are not doing this in the cloud.
Delete the service and create the service like this. Now you could be able to access your application http://<minikube-ip>:30080
apiVersion: v1
kind: Service
metadata:
name: hello-world
spec:
selector:
app: hello-world
ports:
- protocol: "TCP"
port: 80
targetPort: 30080
type: NodePort
LoadBalancer
service is for cloud like AWS/Azure/Google cloud etc. So It can not create any LoadBalancer in your local minikube. There are workarounds to make it work by using externalIPs which you could find here - https://kubernetes.io/docs/concepts/services-networking/service/
To debug this issue, assuming pod is running and appropriate ports are open, create a ClusterIP service.
apiVersion: v1
kind: Service
metadata:
name: hello-world
spec:
selector:
app: hello-world
ports:
- protocol: "TCP"
port: 80
targetPort: 80
type: ClusterIP
Now first check if your application is accessible inside the cluster.
kubectl run busybox --image=busybox --restart=Never -it --rm -- wget -O- http://hello-world/
If it does not work, something is wrong the pod itself!