Spring Authorization Server, Spring Gateway & OAuth Client setup in Kubernetes

73 views Asked by At

I have a microservice that contains from modules:

  • spring-config-server (spring-cloud-config-server);
  • spring-eureka-server (spring-cloud-starter-netflix-eureka-server);
  • spring-authorization-server (spring-boot-starter-oauth2-authorization-server);
  • spring-gateway (spring-cloud-starter-gateway, spring-boot-starter-oauth2-client);
  • spring-resource-server (spring-boot-starter-oauth2-resource-server);
  • client (spring-boot-starter-web, spring-boot-starter-thymeleaf, React app prod build);

I want to work with it in Kubernetes. I am using Minikube for local development. I have started Microservice in Kubernetes since few days ago. I have opened access to gateway using command kubectl port-forward service/spring-cloud-gateway 8090:8090 default page at http://localhost:8090/ I have a problem with Authentication. When I was trying to log in I got an error. Error caused by redirect to OAuth server by URL http://spring-authorization-server:9000/oauth2/authorize visual explanation on the error that is spring:security:oauth2:client:provider:spring:issuer-uri: http://spring-authorization-server:9000, but spring-gateway with this configuration that is also oauth2 client starts successfully when it send starting requests to spring authorization server using it's internal WebClient. I have solved this problem for docker-compose environment by adding to /etc/hosts following lines:

127.0.0.1 spring-cloud-gateway
127.0.0.1 spring-authorization-server

and it does not work with Kubernetes

I have no skill how to solve it now. Maybe Ingress configuration can help here, but I am not sure about it and how to setup Ingress, for example, NGINX Ingress I also do not know. I have tried to chat with ChatGPT and it genered config file for me, but it does not help

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - host: spring-cloud-gateway.local
      http:
        paths:
          - pathType: Prefix
            path: "/"
            backend:
              service:
                name: spring-cloud-gateway
                port:
                  number: 8090
    - host: spring-authorization-server.local
      http:
        paths:
          - pathType: Prefix
            path: "/"
            backend:
              service:
                name: spring-authorization-server
                port:
                  number: 9000

ChatGPT also proposed to add to /etc/hosts ${minikube ip} spring-cloud-gateway.local I added it and it does not help, maybe because I can't to get an access to gateway service using http://${minikube ip}:8090 in the browser and I need to do something with this.

0

There are 0 answers