We are using the networking.k8s.io/v1beta1 and we trying to move to networking.k8s.io/v1 with the following changes and my ingress.YAML code looks like this now.
Version:"v1.20.15-gke.2500"
When I applied the "kubectl apply" I got to see the following error, could someone help me why I am facing this error?
error: error validating "ingress.yaml": error validating data: [ValidationError(Ingress.spec.rules[0].http.paths[0].backend.service.port): invalid type for io.k8s.api.networking.v1.ServiceBackendPort: got "integer", expected "map", ValidationError(Ingress.spec.rules[0].http.paths[1].backend.service.port): invalid type for io.k8s.api.networking.v1.ServiceBackendPort: got "integer", expected "map", ValidationError(Ingress.spec.rules[0].http.paths[2].backend.service.port): invalid type for io.k8s.api.networking.v1.ServiceBackendPort: got "integer", expected "map"; if you choose to ignore these errors, turn validation off with --validate=false
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ***
annotations:
kubernetes.io/ingress.global-static-ip-name: ****
networking.gke.io/managed-certificates: *****
spec:
rules:
- host: ***
http:
paths:
- path: /****/*
pathType: Prefix
backend:
service:
name: *********
port: 50000
- path: /****/*
pathType: Prefix
backend:
service:
name: *********
port: 50000
- path: /****/*
pathType: Prefix
backend:
service:
name: *********
port: 50000
- path: /****/*
pathType: Prefix
backend:
service:
name: *********
port: 50000
- path: /****/*
pathType: Prefix
backend:
service:
name: *********
port: 50000
- path: /****/*
pathType: Prefix
backend:
service:
name: *********
port: 50000
- path: /****/*
pathType: Prefix
backend:
service:
name: *********
port: 50000
- path: /****/*
pathType: Prefix
backend:
service:
name: *********
port: 50000
- host: *********
http:
paths:
- path: /****/*
pathType: Prefix
backend:
service:
name: *********
port: 50000
- path: /****/*
pathType: Prefix
backend:
service:
name: *********
port: 50000
- path: /****/*
pathType: Prefix
backend:
service:
name: *********
port: 50000
You are using the Old format of YAML with API networking.k8s.io/v1 it's updated now.
You can read more here : https://kubernetes.io/docs/concepts/services-networking/ingress/#the-ingress-resource
Change in service port
backend:
service:
name: test
port:
number: 80
Ref YAML block :
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress
spec:
ingressClassName: class-name
rules:
- http:
paths:
- path: /testpath
pathType: Prefix
backend:
service:
name: test
port:
number: 80
You are using incorrect syntax for networking.k8s.io/v1 Ingress. The error is saying that the backend.service.port is no longer an integer, it expects a map.
In apiVersion: networking.k8s.io/v1beta1, the backend section looks like below:
backend:
serviceName: service1
servicePort: 80
Now in apiVersion: networking.k8s.io/v1:
backend:
service:
name: test
port:
number: 80
Sample YAML:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx-example
rules:
- http:
paths:
- path: /testpath
pathType: Prefix
backend:
service:
name: test
port:
number: 80
Related
I have application "test.abc.com". I want to transfer request between different service.
Example or Expected output
when user hit test.abc.com --> it will go to abc-demo-frontend-external service
when user hit test.abc.com/main.js --> it will go to abc-demo-frontend service
I added below code but it is not working
current output
when user hit test.abc.com or test.abc.com/main.js both request going to abc-demo-frontend ? why ?
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-demo-frontend-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: 'false'
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- host: "test.abc.com"
http:
paths:
- path: /*
pathType: ImplementationSpecific
backend:
service:
name: abc-demo-frontend
port:
number: 80
- path: /
pathType: ImplementationSpecific
backend:
service:
name: abc-demo-frontend-external
port:
number: 80
any idea..?
You can try
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-demo-frontend-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: 'false'
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- host: "test.abc.com"
http:
paths:
- path: /(.+\.(css|js))
pathType: ImplementationSpecific
backend:
service:
name: abc-demo-frontend
port:
number: 80
- path: /
pathType: ImplementationSpecific
backend:
service:
name: abc-demo-frontend-external
port:
number: 80
i cannot get pth base nginx routing working. I got host based working. Here is the yaml config
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
name: ingress-resource-3
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-deploy-main
port:
number: 80
- path: /blue
pathType: Prefix
backend:
service:
name: nginx-deploy-blue
port:
number: 80
- path: /green
pathType: Prefix
backend:
service:
name: nginx-deploy-green
port:
number: 80
however host routing works below
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-resource-2
spec:
ingressClassName: nginx
rules:
- host: testingress.cluster.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-deploy-main
port:
number: 80
- host: blue.testingress.cluster.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-deploy-blue
port:
number: 80
- host: green.testingress.cluster.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-deploy-green
port:
number: 80
any idea why path base routing is not working?
also I dont see my hostname when i try to get ingress
[rke#k8gui ingress-demo]$ kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress-resource-3 nginx * 80 11m
I have two domains, I need to redirect those two domains from non-www to www using a single ingress file. Following is my ingress file.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: test
name: test
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: instance
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:ap-south-1:851874770356:certificate/ebdbe046-b0a5-e82324af8533,arn:aws:acm:ap-south-1:8570356:certificate/b1c9-c6dc-4181-bb65-19be8ac479b8
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS":443}]'
alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
alb.ingress.kubernetes.io/actions.redirect-to-www: >
{"Type":"redirect","RedirectConfig":{"Host":"www.domain-1.com","Port":"443","Protocol":"HTTPS","StatusCode":"HTTP_302"}},
{"Type":"redirect","RedirectConfig":{"Host":"www.domain-2.com","Port":"443","Protocol":"HTTPS","StatusCode":"HTTP_302"}
spec:
rules:
- host: domain-1.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: ssl-redirect
port:
name: use-annotation
- path: /
pathType: Prefix
backend:
service:
name: redirect-to-www
port:
name: use-annotation
- host: www.domain-1.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: ssl-redirect
port:
name: use-annotation
- path: /marketing/
pathType: Prefix
backend:
service:
name: "dashboard-api"
port:
number: 3000
- path: /
pathType: Prefix
backend:
service:
name: "api-spa-service"
port:
number: 80
- host: domain-2.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: ssl-redirect
port:
name: use-annotation
- path: /
pathType: Prefix
backend:
service:
name: redirect-to-www
port:
name: use-annotation
- path: /
pathType: Prefix
backend:
service:
name: "admin-spa-service"
port:
number: 80
Now, domain-1.com is working as expected since it is redirecting to www.domain-1.com.
But when I access domain-2.com it is redirecting to www.domain-1.com.
What is wrong with my ingress configuration? Is it not possible to achieve this using a single configuration?
I hosted my web application on AKS cluster in default namespaces.
The cluster uses Nginx Ingress, with host: example.com
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress
namespace: default
spec:
tls:
- hosts:
- example.com
- www.example.com
secretName: tls
defaultBackend:
service:
name: service1
port:
number: 80
rules:
- host: example.com
http:
paths:
- backend:
service:
name: service1
port:
number: 80
path: /
pathType: Prefix
- backend:
service:
name: service1
port:
number: 8080
path: /api
pathType: Prefix
- backend:
service:
name: service1
port:
number: 8080
path: /services
pathType: Prefix
- backend:
service:
name: service1
port:
number: 8080
path: /auth
pathType: Prefix
- backend:
service:
name: service1
port:
number: 8080
path: /websocket
pathType: Prefix
It works well with the simple setting. Nonetheless, some service needs to be separated to another namespaces. We use the same loadbalancer and would like to separate them just with another ingress in another namespaces. No changes were made to the original setting, I have deployed the required services into the new namespace togehter with the ingress as below
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-2
namespace: ns2
spec:
tls:
- hosts:
- new.example.com
- www.new.example.com
secretName: new-tls
defaultBackend:
service:
name: service2
port:
number: 8080
rules:
- host: new.example.com
http:
paths:
- backend:
service:
name: service2
port:
number: 8080
path: /
pathType: Prefix
- backend:
service:
name: service2
port:
number: 8080
path: /api
pathType: Prefix
- backend:
service:
name: service2
port:
number: 8080
path: /services
pathType: Prefix
- backend:
service:
name: service2
port:
number: 8080
path: /auth
pathType: Prefix
- backend:
service:
name: service2
port:
number: 8080
path: /websocket
pathType: Prefix
When I tried to do some test on the config, It turns out that the request always go back to default namespaces service. Any reason?
p.s. service1 and service2 are basically the same, I just need them to handle different request from different domain/subdomain.
Thanks.
I had installed an ran a kubernetes cluster with an nginx ingress earlier this year. Though it had little issues, it worked fine. For the ingress, I used the tag
apiVersion: networking.k8s.io/v1beta1
However, I have recently installed the latest version of (kubernetes 1.22) which only allows for
apiVersion: networking.k8s.io/v1
The problem i'm having is using my old yaml configuration with the new format.
My yaml file looks like this:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: dev-ingress
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: "0"
nginx.ingress.kubernetes.io/websocket-services : "chatserver"
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, OPTIONS"
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- http:
paths:
- path: /api/auth/
pathType: Prefix
backend:
serviceName: um-service
servicePort: 5001
- path: /api/system/*
pathType: Prefix
backend:
serviceName: system-service
servicePort: 5002
- path: /api/news/*
backend:
serviceName: news-service
servicePort: 5003
- path: /api/tasks/*
# pathType: Prefix
backend:
serviceName: tasks-service
servicePort: 5004
- path: /api/chats/
pathType: Prefix
backend:
serviceName: chatserver
servicePort: 5500
- path: /
backend:
serviceName: web-service
servicePort: 5000
my new manifest looks like this:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: dev-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /api/auth/
pathType: Prefix
backend:
service:
name: um-service
port:
number: 5001
- path: /api/system/*
pathType: Prefix
backend:
service:
name: system-service
port:
number: 5002
- path: /api/chats/
pathType: Prefix
backend:
service:
name: chatserver
port:
number: 5050
- path: /
pathType: Prefix
backend:
service:
name: web-service
port:
number: 5000
ingressClassName: nginx
How do I convert this to use the new apiVersion: networking.k8s.io/v1 tag?
Fortunately there isn't too much difference between the API versions in terms of the YAML. Here's an example of networking.k8s.io/v1 from the Kubernetes Docs.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /testpath
pathType: Prefix
backend:
service:
name: test
port:
number: 80
The main change for you would have to do with the how the backend blocks are done. For example:
backend:
serviceName: tasks-service
servicePort: 5004
would need to become:
backend:
service:
name: "tasks-service"
port:
number: 5004