Ingress with single service on docker on mac

5/9/2019

Completely new do K8s here, I'm trying to deploy/connect Ingress to a sample single service on docker for local (docker for mac) and be able to hit it to run the service

1- sample service looks like this (my_service.js) :

const express = require('express')
let app = express()

app.get('/', (req, res) => {
    res.send('Hello service')
})

const PORT = process.env.PORT || 9000
app.listen(
    PORT,
    () => console.log('Listening')
    )

and I build the image (with a docker file):

docker build . -t sample-service-image

2- Now from K8s perspective: here's the deployment file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sample-service
  labels:
    app: sample-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sample-service
  template:
    metadata:
      labels:
        app: sample-service
    spec:
      containers:
      - name: sample-service
        image: sample-service-image
        imagePullPolicy: Never
        ports:
        - containerPort: 9000
kubectl apply -f deployment.yaml

and expose it as a service:

kubectl expose deploy sample-service --type=NodePort

3- Now from Ingress (ingress-sample.yaml) :

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-sample
spec:
  backend:
    serviceName: sample-service
    servicePort: 80
kubectl create -f ingress-sample.yaml

[UPDATE] I deployed an ingress controller from here:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/baremetal/service-nodeport.yaml

this is what I get

$kubectl get ingress
NAME             HOSTS   ADDRESS     PORTS   AGE
ingress-sample   *       localhost   80      8m
kubectl get services --all-namespaces | grep nginx
ingress-nginx   ingress-nginx    NodePort    10.106.47.48     <none>        80:31448/TCP,443:31512/TCP   2h

tried to hit it on http://localhost:31448/ but I get 503 from NGINX ... so I guess it's not properly connected to sample-service.

how should I hit Ingress to be able to call the sample-service?

-- Mahyar
kubernetes
kubernetes-ingress

0 Answers