Here's the thing. I installed a kubernetes cluster on my jelastic account like this:
Then, I wanted to expose a service to the outside of the cluster. The HelloWorld is working out-of-the-box on the cluster, so I thought I could transform it to my needs easily. Upon cluster installation, browsing
my-helloworld-test.my-jelastic-provider.com
works perfectly fine, i.e. I see the hello world html page with styling.
Now, in my future use-cases, I will want to access my services through
my-helloworld-test.my-jelastic-provider.com/hello
or
hello.my-helloworld-test.my-jelastic-provider.com
i.e. I'd like to setup a path for my service or a subdomain. I gathered I need to define an Ingress to make that happen. I've changed the hello-kubernetes
service configuration to this:
kind: Service
apiVersion: v1
metadata:
name: hello-kubernetes
namespace: default
spec:
ports:
- protocol: TCP
port: 80
targetPort: 8080
selector:
app: hello-kubernetes
type: ClusterIP
sessionAffinity: None
externalTrafficPolicy: Cluster
I tried following ingress configuration to define a path to my service:
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: helloworld
namespace: default
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/ssl-redirect: 'false'
spec:
rules:
- http:
paths:
- path: /hello
backend:
serviceName: hello-kubernetes
servicePort: 80
The goal is that browsing
my-helloworld-test.my-jelastic-provider.com/hello
displays the pre-deployed helloworld application, instead of
my-helloworld-test.my-jelastic-provider.com
I could write the helloworld application in such a way that its base url be /hello
, but I learned from several blogs that it is possible to let that happen with kubernetes annotations. In particular, it seems like annotation nginx.ingress.kubernetes.io/rewrite-target
would help, but I was not able to make it happen completely. Indeed, the above configuration shows me the helloworld application when I browse the /hello
path, but unstyled:
How can I make the styling happen?
Another sexy possibility for that service would be to be displayed upon browsing
hello.my-helloworld-test.my-jelastic-provider.com
i.e. as a subdomain of my jelastic environment. I've tried this configuration without success:
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: jenkins
namespace: default
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: 'false'
spec:
rules:
- http:
paths:
- host: hello.my-helloworld-test.my-jelastic-provider.com
path: /
backend:
serviceName: hello-kubernetes
servicePort: 80
What do I need to do to my jelastic environment so that the above host be browsable and exhibits the helloworld application?
Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.6", GitCommit:"7015f71e75f670eb9e7ebd4b5749639d42e20079", GitTreeState:"archive", BuildDate:"2019-11-19T09:00:01Z", GoVersion:"go1.12.12", Co
mpiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.6", GitCommit:"7015f71e75f670eb9e7ebd4b5749639d42e20079", GitTreeState:"archive", BuildDate:"2019-11-19T08:45:41Z", GoVersion:"go1.12.12", Co
mpiler:"gc", Platform:"linux/amd64"}
on jelastic v.5.7.
Looks like there are 2 separate issues atm
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: helloworld
namespace: default
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/ssl-redirect: 'false'
spec:
rules:
- http:
paths:
- path: /hello(/|$)(.*)
backend:
serviceName: hello-kubernetes
servicePort: 80
UPD: We have additionally checked the issue together with Laurent Michel and discovered that problem was caused by absolute URIs in application so rewrite was not applied to CSS/images. Simplest solution - apply two ingress rules with different annotations (one with rewrite and one without). More advanced and correct way to go - shift such applications to separate subdomains so URIs could remain the same.