I'm new to kubernetes and I'm trying to deploy a MEAN stack app with Gitlab pipelines to Kubernetes Engine in Google Cloud. However I just can't get it to let me connect to a pod running my code on an open port (4200). You can find my YAML configs below. Dockerfile
FROM node:13.13-alpine
RUN mkdir -p /usr/src/app
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN cd /usr/src/app && npm install @angular/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4 && npm install && npm run-script build
EXPOSE 3000 4200
CMD ["npm","run-script","start"]
Gitlab-ci.yml
deploy service:
stage: deploy_kubernetes
image: google/cloud-sdk:latest
script:
# Auth and GC Cluster configs
- echo $GKE_SERVICE_KEY | base64 -d > service-account.json
- gcloud auth activate-service-account --key-file service-account.json
- gcloud container clusters get-credentials $GKE_cluster_name --zone $GKE_zone --project $GKE_project_id
# Kompose to build deployment files
- curl -L https://github.com/kubernetes/kompose/releases/download/v1.19.0/kompose-linux-amd64 -o kompose
- chmod +x kompose
- mv ./kompose /usr/local/bin/kompose
- kompose convert -f deploy/docker-compose-stack.yml
# Kompose patches and service creating in Kubernetes
- kubectl apply -f mean-deployment.yaml,mean-service.yaml
- echo $PATCH_LOAD_BALANCER | base64 -d > patch_load_balancer.json
- kubectl patch svc mean --patch "$(cat patch_load_balancer.json)"
docker-compose-stack.yml
version: "3.7"
services:
mean:
image: theycallmefox/gp_ips:latest
ports:
- 3000:3000
- 4200:4200
Running kubectl get svc --all-namespaces gets me the following output:
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 3d
default mean LoadBalancer 10.0.12.199 34.91.94.183 443:31324/TCP,80:32732/TCP,3000:32577/TCP,4200:32512/TCP 2d2h
kube-system default-http-backend NodePort 10.0.4.122 <none> 80:32038/TCP 2d23h
kube-system kube-dns ClusterIP 10.0.0.10 <none> 53/UDP,53/TCP 2d23h
kube-system metrics-server ClusterIP 10.0.1.220 <none> 443/TCP 2d23h
Finally, running kubectl logs -f mean-6cb9949f77-kbz95
> portal-ips@0.0.0 start /usr/src/app
> ng serve && cd ../backend && node app.js
chunk {main} main.js, main.js.map (main) 412 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 141 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {scripts} scripts.js, scripts.js.map (scripts) 219 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 1.12 MB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 5.6 MB [initial] [rendered]
Date: 2020-05-24T17:50:28.305Z - Hash: a02a05a0d81f690bca61 - Time: 35281ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
: Compiled successfully.
Any ideas? Thanks.
You application is listening on localhost, while your load balancer forwards the traffic to the ethernet network interface.
You will need to change your app and make it serve on 0.0.0.0
.