Can't connect to node app on kubernetes

1/23/2018

I've just finished Google's tutorial on how to implement continuous integration for a Go app on Kubernetes using Jenkins, and it works great. I'm now trying to do the same thing with a Node app that is served on port 3001, but I keep getting this error:

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "services \"gceme-frontend\" not found",
  "reason": "NotFound",
  "details": {
    "name": "gceme-frontend",
    "kind": "services"
  },
  "code": 404
}

The only thing I've changed on the routing side is having the load balancer point to 3001 instead of 80, since that's where the Node app is listening. I have a very strong feeling that the error is somewhere in the .yaml files.

My node server (relevant part):

const PORT = process.env.PORT || 3001;

frontend-dev.yaml: (this is applied to the dev environment)

kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: gceme-frontend-dev
spec:
  replicas: 
  template:
    metadata:
      name: frontend
      labels:
        app: gceme
        role: frontend
        env: dev
    spec:
      containers:
      - name: frontend
        image: gcr.io/cloud-solutions-images/gceme:1.0.0
        resources:
          limits:
            memory: "500Mi"
            cpu: "100m"
        imagePullPolicy: Always
        ports:
          - containerPort: 3001
            protocol: TCP

services/frontend.yaml:

kind: Service
apiVersion: v1
metadata:
  name: gceme-frontend
spec:
  type: LoadBalancer
  ports:
  - name: http
      #THIS PORT ACTUALLY GOES IN THE URL: i.e. gcme-frontend: ****
      #when it says "no endpoints available for service, that doesn't mean this one is wrong, it means that target port is not working not exist"
    port: 80
      #matches port and -port in frontend-*.yaml
    targetPort: 3001
    protocol: TCP
  selector:
    app: gceme
    role: frontend

Jenkinsfile (for dev branches, which is what I'm trying to get working)

sh("kubectl get ns ${env.BRANCH_NAME} || kubectl create ns ${env.BRANCH_NAME}")
// Don't use public load balancing for development branches
sh("sed -i.bak 's#LoadBalancer#ClusterIP#' ./k8s/services/frontend.yaml")
sh("sed -i.bak 's#gcr.io/cloud-solutions-images/gceme:1.0.0#${imageTag}#' ./k8s/dev/*.yaml")
sh("kubectl --namespace=${env.BRANCH_NAME} apply -f k8s/services/")
sh("kubectl --namespace=${env.BRANCH_NAME} apply -f k8s/dev/")
echo 'To access your environment run `kubectl proxy`'
echo "Then access your service via http://localhost:8001/api/v1/proxy/namespaces/${env.BRANCH_NAME}/services/${feSvcName}:80/"
-- Artem Zakharov
google-kubernetes-engine
jenkins
kubernetes

1 Answer

1/23/2018

Are you creating Service or Ingress resources to expose your application to the outside world?

See tutorials:

which have working examples you can copy and modify.

-- AhmetB - Google
Source: StackOverflow