I’ve built a deployment, service and ingress however I fail to reach it on my local web (using minikube).
I’ve just uploaded a random HTML to my github user, and this "app" is just cloning my git repo containing the HTML file to the container and I try to reach it locally..
My Deployment file: (My container is working well 100%).
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: ourapp
image: nginx:latest
ports:
- containerPort: 80
volumeMounts:
- name: cdn
mountPath: /usr/share/nginx/html
initContainers:
- name: init
image: alpine/git:latest
volumeMounts:
- name: cdn
mountPath: /home/cdn
command: ["/bin/sh", "-c"]
args: ['git clone $GIT_CLONE /home/cdn']
env:
- name: GIT_CLONE
valueFrom:
configMapKeyRef:
name: config-map
key: kvsource
volumes:
- name: cdn
emptyDir: {}
My service file:
apiVersion: v1
kind: Service
metadata:
name: my-cip-service
spec:
selector:
app: nginx
type: ClusterIP
ports:
- protocol: TCP
port: 80
targetPort: 8080
I’ve applied the ingress addon on Minikube and generated the following ingress file:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress
spec:
rules:
- host: localhost
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-cip-service
port:
number: 80
However I still unable to reach my app at localhost/ address..
I’m stuck on it for a long time.. Do you see anything wrong here?
2
Answers
Firstly I think, you need to change your service
targetPort
to 80. Secondly, while working on minikube, you need to setup a entry in your system’shosts
file with ingress host (localhost
in your case) pointing to the minikube node ip.As you’re just testing, change ingress host to something like
example.com
for your own clarity. And you can get the node ip by just typingminikube ip
. So, create an entry forexample.com
pointing tominikube ip
and try hittingexample.com
.When using minikube it does not mean that your applications will be accessible on localhost.
When ingress addon is enabled for minikube, you can reach it (ingress controller) under minikube VM ip.
You can get this ip by running
minikube ip
command.If you want to use your own domain locally (assuming you run on linux or mac) run:
It will add one line to you hosts file pointing domain.test to minikube ip.
Now you can use this domain in your ingress file:
Additionally, you have a misconfigured service. TargetPort field should be set to the port number that the application is listening on. As far as I know, nginx image listens on port 80 by default and so targetPort of associated service should be set to this value.
From now on you should be able to reach your website locally under http://domain.test.