I have deployed nginx :
kubectl run nginx --image=nginxAnd I exposed nginx
kubectl expose deployment nginx --port 80 --type NodePortAnd when execute this command
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx NodePort 10.254.237.40 <none> 80:31111/TCP 22s
jenkins ClusterIP 10.254.118.81 <none> 8080/TCP 45m
And I deployed Ingress file
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: example.com
http:
paths:
- path: /jenkins
backend:
serviceName: jenkins
servicePort: 8080And to know Output of ingress
-> kubectl apply -f ingress.yaml
ingress.extensions "nginx" configured
-> kubectl get ing
NAME HOSTS ADDRESS PORTS AGE
nginx example.com 80 40m
And when Browser
http://Node-IP:31111
Returns Nginx's Welcome Page
And When Browser
http://http://Node-IP:31111/jenkins
Returns 404 Not FoundIs there something I do not understand?
And How to Solve this Issue?
thank you :D
You are not supposed to use the Node-IP if you want to get to the jenkins endpoint. In this case, you need to use example.com. But you need the Layer 7 Host header so that the ingress understands it. To test it, you need to modify it. A couple of ways you can do it:
Try running:
curl -H 'Host: example.com' http://Node-IP:31111/jenkinsModify the /etc/hosts to have an entry Node-IP example.comfile on your machine and just browse to:
http://example.com:31111/jenkinsNote that you are using a NodePort for you service. You can use a LoadBalancer type to avoid specifying the port. (Use the default port 80). You can also use the clusterIP 10.254.237.40, but to access it you would have to be in one the machines in your Kubernetes cluster.
It seems that you deployed in a way that doesnt include the functionality required to watch Ingress resources in kubernetes.
I recommend that you deploy nginx-ingress in an officially suggested manner: https://kubernetes.github.io/ingress-nginx/deploy/#generic-deployment
I personally recommend the helm chart option: https://kubernetes.github.io/ingress-nginx/deploy/#using-helm
NGINX Ingress controller can be installed via Helm using the chart stable/nginx-ingress from the official charts repository. To install the chart with the release name my-nginx:
helm install stable/nginx-ingress --name my-nginx If the kubernetes cluster has RBAC enabled, then run:
helm install stable/nginx-ingress --name my-nginx --set rbac.create=true Detect installed version:
POD_NAME=$(kubectl get pods -l app.kubernetes.io/name=ingress-nginx -o jsonpath='{.items[0].metadata.name}') kubectl exec -it $POD_NAME -- /nginx-ingress-controller --version
In addition, see the above answer by @Rico regarding passing the correct host headers:
Try running:
curl -H 'Host: example.com' http://Node-IP:31111/jenkinsModify the
/etc/hoststo have an entryNode-IP example.comfile on your machine and just browse to:http://example.com:31111/jenkins