Support ingress path for kubernetes (#1245)

* Support ingress path for kubernetes
This commit is contained in:
Hang Yan 2020-02-23 19:25:43 +08:00 committed by GitHub
parent 49d8133fb9
commit 1685ab3001
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 5 deletions

View File

@ -332,7 +332,7 @@ services:
```
- `kompose.service.expose` defines if the service needs to be made accessible from outside the cluster or not. If the value is set to "true", the provider sets the endpoint automatically, and for any other value, the value is set as the hostname. If multiple ports are defined in a service, the first one is chosen to be the exposed.
- For the Kubernetes provider, an ingress resource is created and it is assumed that an ingress controller has already been configured. If the value is set to a comma sepatated list, multiple hostnames are supported.
- For the Kubernetes provider, an ingress resource is created and it is assumed that an ingress controller has already been configured. If the value is set to a comma sepatated list, multiple hostnames are supported.Hostname with path is also supported.
- For the OpenShift provider, a route is created.
- `kompose.service.nodeport.port` defines the port value when service type is `nodeport`, this label should only be set when the service only contains 1 port. Usually kubernetes define a port range for node port values, kompose will not validate this.
- `kompose.service.expose.tls-secret` provides the name of the TLS secret to use with the Kubernetes ingress controller. This requires kompose.service.expose to be set.

View File

@ -462,11 +462,13 @@ func (k *Kubernetes) initIngress(name string, service kobject.ServiceConfig, por
}
for i, host := range hosts {
host, p := transformer.ParseIngressPath(host)
ingress.Spec.Rules[i] = extensions.IngressRule{
IngressRuleValue: extensions.IngressRuleValue{
HTTP: &extensions.HTTPIngressRuleValue{
Paths: []extensions.HTTPIngressPath{
{
Path: p,
Backend: extensions.IngressBackend{
ServiceName: name,
ServicePort: intstr.IntOrString{

View File

@ -103,6 +103,16 @@ func ParseVolume(volume string) (name, host, container, mode string, err error)
return
}
// ParseIngressPath parse path for ingress.
// eg. example.com/org -> example.com org
func ParseIngressPath(url string) (string, string) {
if strings.Contains(url, "/") {
splits := strings.Split(url, "/")
return splits[0], "/" + splits[1]
}
return url, ""
}
func isPath(substring string) bool {
return strings.Contains(substring, "/") || substring == "."
}

View File

@ -5,7 +5,7 @@ web:
links:
- redis
labels:
kompose.service.expose: " batman.example.com ,, batwoman.example.com "
kompose.service.expose: " batman.example.com/home ,, batwoman.example.com "
redis:
image: redis:3.0
ports:

View File

@ -44,7 +44,7 @@
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.service.expose": " batman.example.com ,, batwoman.example.com ",
"kompose.service.expose": " batman.example.com/home ,, batwoman.example.com ",
"kompose.version": "%VERSION%"
}
},
@ -125,7 +125,7 @@
"metadata": {
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.service.expose": " batman.example.com ,, batwoman.example.com ",
"kompose.service.expose": " batman.example.com/home ,, batwoman.example.com ",
"kompose.version": "%VERSION%"
},
"creationTimestamp": null,
@ -146,7 +146,7 @@
"metadata": {
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.service.expose": " batman.example.com ,, batwoman.example.com ",
"kompose.service.expose": " batman.example.com/home ,, batwoman.example.com ",
"kompose.version": "%VERSION%"
},
"creationTimestamp": null,
@ -193,6 +193,7 @@
"http": {
"paths": [
{
"path": "/home",
"backend": {
"serviceName": "web",
"servicePort": 5000