Code Monkey home page Code Monkey logo

Comments (2)

waleedhere avatar waleedhere commented on May 16, 2024

I'm facing the same issue. Were you able to find the solution??

from kanban-board.

TormentedTraveler avatar TormentedTraveler commented on May 16, 2024

I encountered the same issue while deploying the application in Kubernetes and managed to resolve it. The problem originated from two main areas: CORS settings in the Java application and network configuration in the deployment setup.

CORS Configuration in Java Controllers

The Java application restricts CORS to requests only from http://localhost:4200. This is specified in the controllers KanbanController.java and TaskController.java in path kanban-app/src/main/java/com/wkrzywiec/medium/kanban/controller/ with the following annotations:

@CrossOrigin(origins = "http://localhost:4200")

To allow requests from any origin, I updated this setting to:

@CrossOrigin(origins = "*")

Networking Configuration in the Nginx Proxy:

In the kanban-ui service, the default configuration routes traffic to backend paths which aren't reachable in a Kubernetes environment. The relevant settings in kanban-ui/default.conf are:

location /api/kanbans {
    proxy_pass http://kanban-app:8080/api/kanbans;
}
location /api/tasks {
    proxy_pass http://kanban-app:8080/api/tasks;
}

Here, http://kanban-app:8080 points to a service name defined in Docker Compose, which does not work in Kubernetes unless specifically configured.

There are multiple ways to make it work in Kubernetes, they depend on how do you expose you backend, it might be NodePort, LoadBalancer (LB), or Ingress. Here's how it can be done:
-For a LoadBalancer or Ingress, simply replace http://kanban-app:8080 with the external URL provided by your Kubernetes deployment.
-For NodePort, you need to specify the external IP and port. I automated this with a script to add the IP of machine to /etc/hosts, making the service reachable inside the cluster:

Script to Modify /etc/hosts:

#!/bin/sh
echo "$(curl -s ifconfig.me) kanban-app" >> /etc/hosts
nginx -g "daemon off;"

This script is included and executed in the Dockerfile for the kanban-ui component. Place script in kanban-ui\add-ip-address-to-hosts.sh

Modified Dockerfile (file path: kanban-ui\Dockerfile):

### STAGE 1: Build ###
FROM node:12.7-alpine AS build
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install
COPY . .
RUN npm run build

### STAGE 2: Run ###
FROM nginx:1.17.1-alpine
RUN apk update && apk add curl
COPY default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /usr/src/app/dist/kanban-ui /usr/share/nginx/html
COPY --from=build /usr/src/app/add-ip-address-to-hosts.sh /
CMD ["sh", "/add-ip-address-to-hosts.sh"]
EXPOSE 80

Lastly, I updated the proxy port in the Nginx configuration to match the NodePort:

location /api/kanbans {
    proxy_pass http://kanban-app:30000/api/kanbans;
}
location /api/tasks {
    proxy_pass http://kanban-app:30000/api/tasks;
}

from kanban-board.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.