0
votes

I currently have a Dockerised Spring Boot application with exposed Java REST APIs that I deploy on to my NUC (just a remote machine) and can connect to it from my Mac, via the NUCs static IP address. Both machines are on the same network.

I am now looking into hosting the Docker application in Kubernetes (Minikube)
(using this tutorial https://medium.com/bb-tutorials-and-thoughts/how-to-run-java-rest-api-on-minikube-4b564ea982cc).

I have used the Kompose tool from Kubernetes to convert my Docker compose files into Kubernetes deployments and services files. One of the services I'm trying to get working first simply opens up port 8080 and has a number of REST resources. Everything seems to be up and running, but I cannot access the REST resources from my Mac (or even the NUC itself) with a curl -v command.

After getting around a small issue with my Docker images (needing built to Minikube's internal Docker images repo), I can successfully deploy my services and deployments. There are a number of others, but for the purposes of getting past this step, I'll just include the one:

$ kubectl get po -A

NAMESPACE         NAME                                 READY   STATUS    RESTARTS   AGE
kube-system       coredns-f9fd979d6-hhgn8              1/1     Running   0          7h
kube-system       etcd-minikube                        1/1     Running   0          7h
kube-system       kube-apiserver-minikube              1/1     Running   0          7h
kube-system       kube-controller-manager-minikube     1/1     Running   0          7h
kube-system       kube-proxy-rszpv                     1/1     Running   0          7h
kube-system       kube-scheduler-minikube              1/1     Running   0          7h
kube-system       storage-provisioner                  1/1     Running   0          7h
meanwhileinhell   apigw                                1/1     Running   0          6h54m
meanwhileinhell   apigw-75bc5z1f5j-cklxt               1/1     Running   0          6h54m
$ kubectl get service apigw

NAME         TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
apigw        NodePort   10.107.116.239   <none>        8080:32327/TCP   6h53m
$ kubectl cluster-info

Kubernetes master is running at https://192.168.44.2:8443
KubeDNS is running at https://192.168.44.2:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

However, I cannot hit this master IP address, or any expected open port using the static IP of my NUC. I have tried to use the service types LoadBalancer and NodePort for the service but the former hangs on pending for the external IP.

I have played about a little with exposing ports and port forwarding but haven't been able to get anything working (port 7000 is just an arbitrary number):

kubectl port-forward apigw 7000:8080
kubectl expose deployment apigw --port=8080 --target-port=8080

Here is my apigw deployment, service and pod yaml files:

apigw-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: apigw
  name: apigw
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: apigw
  strategy:
    type: Recreate
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.network/networkinhell: "true"
        io.kompose.service: apigw
    spec:
      containers:
          image: meanwhileinhell/api-gw:latest
          name: apigw
          ports:
            - containerPort: 8080
          resources: {}
          imagePullPolicy: Never
          volumeMounts:
            - mountPath: /var/log/gateway
              name: combined-logs
      hostname: apigw
      restartPolicy: Always
      volumes:
        - name: combined-logs
          persistentVolumeClaim:
            claimName: combined-logs
status: {}

apigw-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: apigw
  labels:
    run: apigw
spec:
  ports:
  - port: 8080
    protocol: TCP
  selector:
    app: apigw
  type: NodePort

apigw-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: apigw
  name: apigw
spec:
  containers:
    - image: meanwhileinhell/api-gw:latest
      name: apigw
      imagePullPolicy: Never
      resources: {}
      ports:
        - containerPort: 8080

Using kubectl create -f to create the services.

Ubuntu 18.04.5 LTS
Minikube v1.15.0
KubeCtl v1.19.4
What minikube --driver are you using?Matt
Hi Matt, I'm using the Linux Docker driver minikube config set driver dockerMeanwhileInHell
Are you running kubectl from your Mac? or the remote host?Matt
I am running it from the remote host.MeanwhileInHell
Try kubectl port-forward apigw 7000:8080 --address 0.0.0.0Matt