how to setup an Angular multi language site + google cloud kubernetes

5/22/2021

We're upgrading our working single language site to a multi language site. we have developed this in angular an locally it works (on 2 different urls). when uploading this to the google cloud it gives a lot of problems.

the ideal situations is that we have 1 site "example.com" that auto redirects to "example.com/nl" and 1 site that is "example.com/en" but I dont know what is wrong with our setup.

This is our angular.json file:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "xxxxxxxxxx": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        },
        "@schematics/angular:application": {
          "strict": true
        }
      },
      "i18n": {
        "sourceLocale": {
          "code": "nl",
          "baseHref": "/nl"
        },
        "locales": {
          "en": {
            "translation": "src/locale/messages.en.xlf",
            "baseHref": "/en"
          }
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/xxxxx",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "localize": true,
            "assets": [
              "src/assets/imgs/favicon.png",
              "src/assets",
              {
                "glob": "**/*",
                "input": "./node_modules/svg-country-flags/svg",
                "output": "src/assets/svg-country-flags/svg"
              }
            ],
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/purple-green.css",
              "src/styles.scss",
              "src/theme.scss",
              "node_modules/bootstrap/dist/css/bootstrap.css",
              "node_modules/@fortawesome/fontawesome-free/css/all.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.js",
              "node_modules/bootstrap/dist/js/bootstrap.js",
              "node_modules/@fortawesome/fontawesome-free/js/all.js"
            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "3mb", //initial 500kb
                  "maximumError": "4mb" //initial 1mb
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "100kb", //initial 2kb
                  "maximumError": "150kb" //initial 4kb
                }
              ]
            },
            "development": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.dev.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "3mb", //initial 500kb
                  "maximumError": "4mb" //initial 1mb
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "100kb", //initial 2kb
                  "maximumError": "150kb" //initial 4kb
                }
              ]
            },
            "en": {
              "localize": [ "en" ],
              "baseHref": "/en"
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "xxxxxx:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "xxxxxx:build:production"
            },
            "development": {
              "browserTarget": "xxxxxx:build:development"
            },
            "eng": {
              "browserTarget": "xxxxxx:build:eng"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "xxxxxxx:build",
            "outputPath": "src/locale/"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/purple-green.css",
              "src/styles.scss"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "xxxxxxxx:serve"
          },
          "configurations": {
            "development": {
              "devServerTarget": "xxxxxxxxxxx:serve:development"
            },
            "production": {
              "devServerTarget": "xxxxxxxxx:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "xxxxxxxxxx"
}

and in the cloud we have this as our ingress yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: gce
    kubernetes.io/ingress.global-static-ip-name: xxxxxxxxxx
    networking.gke.io/managed-certificates: "xxxxxxxxxxxx"
  name: xxxxxxxxxxx
  namespace:xxxxxxxxx
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /nl
        backend:
          serviceName: xxxxxxxxx-nl-service
          servicePort: 80
      - path: /en
        backend:
          serviceName: xxxxxxxxx-en-service
          servicePort: 80

and the dockerfile-en:

### STAGE 1: Build ###

FROM node:12.7-alpine AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build --prod

### STAGE 2: Run ###
FROM nginx:1.17.1-alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /app/dist/xxxxxxx/en /usr/share/nginx/html/en
-- Ties Theunissen
angular
google-cloud-platform
kubernetes
multilingual

0 Answers