I am trying to run the Docker images from gitlab-registry in Google Kubernetes Engine in a cluster and have traffic flow through ingress nginx controller. I am not able to achieve it. Here is the proper explanation. I build a pipeline using gitlab ci/cd and each time a pipeline is a success it pushes a docker image to gitlab registry. Now I want to test that images stored in the gitlab registry. I need to pull them and run containers from that images in the kubernetes cluster in Google Kubernetes Engine. I tried a lot of ways but a few errors keep coming. for example:/built_app/programs/server/node_modules/fibers/future.js:313 throw(ex); ^ MongoError: failed to connect to server [cluster1-shard-00-02-iqf6c.mongodb.net:27017] on first connect [MongoError: connection 5 to cluster1-shard-00-02-iqf6c.mongodb.net:27017 timed out] at Pool.<anonymous> (/built_app/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/topologies/server.js:336:35) at emitOne (events.js:116:13) at Pool.emit (events.js:211:7) at Connection.<anonymous> (/built_app/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/pool.js:280:12) at Object.onceWrapper (events.js:317:30) at emitTwo (events.js:126:13) at Connection.emit (events.js:214:7) at TLSSocket.<anonymous> (/built_app/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/connection.js:199:10) at Object.onceWrapper (events.js:313:30)
I tried to set the environmental variables as a secret in the kubernetes cluster and used them. and also I created one more secret to use it for pulling images from the private gitlab registry.
I also have a Nginx-ingress-controller setup by the gitlab while integrated the kubernetes cluster with Gitlab.
I want to connect and test these docker images from the internet using the Ingress and the GKE. I am stuck here without any idea. Any help would be great for a beginner like me.
I have the kubernetes cluster integrated with gitlab CI and this integration have already installed some apps like ingress-nginx-controller, gitlab-runner and other on my cluster in GKE.
Here I am attaching the YAML files used in GKE.
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-one
namespace: gitlab-managed-apps
labels:
app: myapp
spec:
replicas: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: mycontainer
image: my-image-from-private-gitlab-registry
ports:
- containerPort: 80
env:
- name: MONGO_URL
valueFrom:
secretKeyRef:
name: envisec
key: MONGO_URL
- name: ROOT_URL
valueFrom:
secretKeyRef:
name: envisec
key: ROOT_URL
- name: PORT
valueFrom:
secretKeyRef:
name: envisec
key: PORT
ports:
- containerPort: 80
imagePullSecrets:
- name: myreg
---
apiVersion: v1
kind: Service
metadata:
name: myapp-service
namespace: gitlab-managed-apps
labels:
app : myapp
spec:
type: LoadBalancer
ports:
- port: 80
protocol: TCP
selector:
app: myapp
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: myapp-ingress
namespace: gitlab-managed-apps
spec:
rules:
- http:
paths:
- path: /hello
backend:
serviceName: myapp-service
servicePort: 80
these are the yaml fileS which I've been using. The mongodb which we use use is hosted on another service. The connection is not being made with mongoDB and I am stuck here. I am stuck and any help would be appreciated..
By default, GKE gives you the possibility to create HTTP(S) Load Balancer, once you deploy the Ingress resource on Kubernetes cluster. You might also need to switch the nested Pod service to NodePort
, this is in order to route the network traffic to the application. You can check the External IP address for Load Balancer by the following command:
kubectl get ingress myapp-ingress
Based on the configuration that you have provided, I would suggest replacing LoadBalancer
with NodePort
parameter. You can get more information in the Official Google Cloud Documentation.