I am working with NextJS and I need for it to know when it's making a request on the server or on the browser. To do it on the server-side because I am building this inside a microservices architecture, I need to obtain the service name and namespace of the service to complete the url like so http://SERVICENAME.NAMESPACE.svc.cluster.local
.
So in my terminal I printed out all my different namespaces like so:
$kubectl get namespace
NAME STATUS AGE
default Active 9d
ingress-nginx Active 9d
kube-node-lease Active 9d
kube-public Active 9d
kube-system Active 9d
So ingress-nginx
is what I am looking for. Then I ran:
$kubectl get services -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller LoadBalancer 10.100.129.149 localhost 80:30463/TCP,443:31399/TCP 9d
ingress-nginx-controller-admission ClusterIP 10.111.40.184 <none> 443/TCP 9d
So to my understanding ingress-nginx-controller
is the name of my service.
So I am making the request to http://ingress-nginx.ingress-nginx-controller.svc.cluster.local/api/users/currentuser
, but I also had to specify a host like so:
LandingPage.getInitialProps = async () => {
if (typeof window === "undefined") {
const { data } = await axios.get(
"http://ingress-nginx.ingress-nginx-controller.svc.cluster.local/api/users/currentuser",
{
headers: {
Host: "ticketing.dev",
},
}
);
return data;
} else {
const { data } = await axios.get("/api/users/currentuser");
return data;
}
};
but when I make the request I am still getting this printing out on the browser:
I pulled kubectl
logs and everything is 200
:
192.168.65.3 - - [06/Nov/2020:01:30:15 +0000] "GET /_next/static/chunks/pages/_app.js?ts=1604626215582 HTTP/2.0" 200 600778 "https://ticketing.dev/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" 51 0.131 [default-client-srv-3000] [] 10.1.0.244:3000 601240 0.132 200 406761022b9aad1a8cd45b9574f3082c
192.168.65.3 - - [06/Nov/2020:01:30:15 +0000] "GET /_next/static/chunks/main.js?ts=1604626215582 HTTP/2.0" 200 1141017 "https://ticketing.dev/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" 46 0.259 [default-client-srv-3000] [] 10.1.0.244:3000 1141886 0.258 200 da2d882e400bebe57a8ce403acd55c8b
192.168.65.3 - - [06/Nov/2020:01:30:16 +0000] "GET /_next/static/chunks/0.js HTTP/2.0" 200 1578 "https://ticketing.dev/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" 32 0.003 [default-client-srv-3000] [] 10.1.0.244:3000 1595 0.003 200 264ab274cf006691d92b1f03f05ffbca
192.168.65.3 - - [06/Nov/2020:01:30:27 +0000] "GET /_next/webpack-hmr?page=/ HTTP/2.0" 200 1499 "https://ticketing.dev/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" 34 11.495 [default-client-srv-3000] [] 10.1.0.244:3000 1543 11.495 200 99420f1d80b74b84c0cb42ead9981d43
What am I missing? I don't think the issue is in the ingress-srv.yml
file:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- host: ticketing.dev
http:
paths:
- path: /api/users/?(.*)
backend:
serviceName: auth-srv
servicePort: 3000
- path: /?(.*)
backend:
serviceName: client-srv
servicePort: 3000
What should I exactly do to reload my ingress? You just need to update the ingress, in your case you just need to add the TLS section is to existing Ingress. Then (automatically) the ingress controller should find the differences (as anemyte says in its answer) and update the ingress.
If you need to determine the version of the nginx ingress controller deployed, then you can invoke the ingress controller binary with the '–version' flag. But this binary is located in the ingress-nginx-controller pod, so do a 'kubectl exec' like below.
You should be able to view them the same as any other pod ( kubectl logs -n namespace-name pod-name ). The name and namespace will change depending on which ingress controller you're using.
Base on URL of accessing the service:
http://SERVICENAME.NAMESPACE.svc.cluster.local
so it should be
http://ingress-nginx-controller.ingress-nginx.svc.cluster.local
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With