skip to Main Content

I have a cloud instance up & running, I installed minikube on it and created a cluster, single Pod with NodePort service.

I know that this is not the best practice while setup kubernetes cluster

The issue is :
Everything works fine if tested from inside the host machine (the cloud instance) but I am trying to reach the cluster from outside the machine using it’s external-ip address, how to do that?

Deployment: the image is public if you want to test

apiVersion: apps/v1
kind: Deployment
metadata:
  name: python-app-deployment
spec:
  template:
    metadata:
      labels:
        tag: pythonapp
    spec:
      containers:
        - name: pythonapp
          image: atefhares/mypythonapp:latest
          ports:
            - containerPort: 8000
          env:
            - name: ENVIRONMENT
              value: DEV
            - name: HOST
              value: "localhost"
            - name: PORT
              value: "8000"
            - name: REDIS_HOST
              value: "redis-service"
            - name: REDIS_PORT
              value: "6379"
            - name: REDIS_DB
              value: "0"
  replicas: 1
  selector:
    matchLabels:
      tag: pythonapp

Service:

apiVersion: v1
kind: Service
metadata:
  name: python-app-service
spec:
  type: NodePort
  ports:
    - nodePort: 30001
      port: 8000
  selector:
    tag: pythonapp

Database deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis
spec:
  template:
    metadata:
      labels:
        name: redis
    spec:
      containers:
        - name: redis
          image: redis:latest
          ports:
            - containerPort: 6379
  selector:
      matchLabels:
        name: redis

Database service:

apiVersion: v1
kind: Service
metadata:
  name: redis-service
spec:
  ports:
  - port: 6379
    protocol: TCP
  selector:
    name: redis

2

Answers


  1. Chosen as BEST ANSWER

    The issue is because minkube creates a VM or a docker container to be used as worker/node. that's why the cluster is not by default accessible from outside the machine.

    To fix this issue use minikube without drivers as follows:

    sudo minikube start --driver=none
    

    This will enforce minikube to not create any VMs or Containers and will directly use resources from the host.

    Also, make sure everything works fine in your deployment and you will be able to access the cluster using the machine's external-ip address and service port.

    Know more here


    PS: This is not a setup for production environments!


  2. With minikube, you have to expose the service also with minikube.

    Example:
    minikube service yourservicename [1]

    You can list all your minikube services with minikube service list

    [1]https://kubernetes.io/docs/tutorials/hello-minikube/#create-a-service

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search