How to expose MinIO outside cluster ip

Viewed 396

I have setup MinIO with Kubernetes (K3s) in one node.

Command kubectl logs mypod-0 -n minio returns the following:

I have access to the console from the second link and by using python I can list the buckets inside minio with:

import logging
from minio import Minio
from minio.error import S3Error

# execute from IDE terminal
minio = Minio(
    '10.42.0.14:9000',
    access_key='chesAccesskeyMinio',
    secret_key='chesSecretkey',
    secure=False,
)


def list_all_buckets():
    bucket_list = minio.list_buckets()
    for bucket in bucket_list:
        objects = minio.list_objects(bucket.name, recursive=True)
        print (bucket.name)

if __name__ == '__main__':
    try:
        list_all_buckets()
    except S3Error as exc:
        print("error occurred.", exc)
        logging.critical("Object storage not reachable")

My question is how to expose this IP to be accesible from outside my network (both he console and the API). Do I have to use ingress?

UPDATED based on answer and comments

I have two services

apiVersion: v1
kind: Service
metadata:
  name: ches
  namespace: minio
  labels:
    app: ches
spec:
  clusterIP: None
  selector:
    app: ches
  ports:
  - port: 9011
    name: ches
---
apiVersion: v1
kind: Service
metadata:
  name: ches-service
  namespace: minio
  labels:
    app: ches
spec:
  type: LoadBalancer
  selector:
    app: ches
  ports:
  - port: 9012
    targetPort: 9011
    protocol: TCP

and then I created an Ingress using

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minio
  namespace: minio
spec:
  rules:
  - host: s3.example.com
    http:
      paths:
      - backend:
          service:
            name: ches-service
            port:
              number: 9000
        path: /
        pathType: Prefix

Command kubectl describe Ingress minio -n minio results in:

Name:             minio
Namespace:        minio
Address:          192.168.1.14
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host            Path  Backends
  ----            ----  --------
  s3.example.com  
                  /   ches-service:9000 (10.42.0.14:9011)
Annotations:      <none>
Events:           <none>

However I cannot access s3.example.com.

Am I missing something here?

1 Answers

Yes, an Ingress would allow you to expose MinIO to clients outside your clusters SDN.

You probably have a Service object already (if not, you need one, Ingress points to Service, which resolves to Pods).

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minio
spec:
  rules:
  - host: s3.example.com
    http:
      paths:
      - backend:
          service:
            name: minio-api
            port:
              number: 9000
        path: /
        pathType: Prefix

If you don't have/want to use an ingresscontroller, you could use a NodePort service:

apiVersion: v1
kind: Service
metadata:
  name: minio-nodeport
spec:
  ports:
  - name: http
    port: 9000
    targetPort: 9000
  selector:
    name: my-minio-pod
  type: NodePort

NodePorts services are allocated a unique port (within a range/could vary depending on your cluster configuration). When connecting to any node of your cluster, on that port, we would be redirected to any pod matching that Services selector.

$> kubectl get svc
my-nodeport-svc  NodePort 10.233.7.160 <none> 9000:32133/TCP

Getting my service, after its creation, I can see that I can reach port 9000 (in SDN), when connecting to port 32133 (outside SDN). You can "kubectl get nodes -o wide", to get a list of your nodes IP addresses, all of which would forward connections to your Pods

Related