How do I connect to a minio pod using the python API?

Question:

I set up a microk8s deployment with the Minio service activated. I can connect to the Minio dashboard with a browser but cannot find a way to connect to the service via the API.

Here is the output to the microk8s kubectl get all --all-namespaces command

NAMESPACE        NAME                                            READY   STATUS    RESTARTS      AGE
minio-operator   pod/minio-operator-67dcf6dd7c-vxccn             0/1     Pending   0             7d22h
kube-system      pod/calico-node-bpd4r                           1/1     Running   4 (26m ago)   8d
kube-system      pod/dashboard-metrics-scraper-7bc864c59-t7k87   1/1     Running   4 (26m ago)   8d
kube-system      pod/hostpath-provisioner-69cd9ff5b8-x664l       1/1     Running   4 (26m ago)   7d22h
kube-system      pod/kubernetes-dashboard-dc96f9fc-4759w         1/1     Running   4 (26m ago)   8d
minio-operator   pod/console-66c4b79fbd-mw5s8                    1/1     Running   3 (26m ago)   7d22h
kube-system      pod/calico-kube-controllers-79568db7f8-vg4q2    1/1     Running   4 (26m ago)   8d
kube-system      pod/coredns-6f5f9b5d74-fz7v8                    1/1     Running   4 (26m ago)   8d
kube-system      pod/metrics-server-6f754f88d-r7lsj              1/1     Running   4 (26m ago)   8d
minio-operator   pod/minio-operator-67dcf6dd7c-8dnlq             1/1     Running   9 (25m ago)   7d22h
minio-operator   pod/microk8s-ss-0-0                             1/1     Running   9 (25m ago)   7d22h

NAMESPACE        NAME                                TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default          service/kubernetes                  ClusterIP   10.152.183.1     <none>        443/TCP                  11d
kube-system      service/kube-dns                    ClusterIP   10.152.183.10    <none>        53/UDP,53/TCP,9153/TCP   8d
kube-system      service/metrics-server              ClusterIP   10.152.183.43    <none>        443/TCP                  8d
kube-system      service/kubernetes-dashboard        ClusterIP   10.152.183.232   <none>        443/TCP                  8d
kube-system      service/dashboard-metrics-scraper   ClusterIP   10.152.183.226   <none>        8000/TCP                 8d
minio-operator   service/operator                    ClusterIP   10.152.183.48    <none>        4222/TCP,4221/TCP        7d22h
minio-operator   service/console                     ClusterIP   10.152.183.193   <none>        9090/TCP,9443/TCP        7d22h
minio-operator   service/minio                       ClusterIP   10.152.183.195   <none>        80/TCP                   7d22h
minio-operator   service/microk8s-console            ClusterIP   10.152.183.192   <none>        9090/TCP                 7d22h
minio-operator   service/microk8s-hl                 ClusterIP   None             <none>        9000/TCP                 7d22h

NAMESPACE     NAME                         DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
kube-system   daemonset.apps/calico-node   1         1         1       1            1           kubernetes.io/os=linux   8d

NAMESPACE        NAME                                        READY   UP-TO-DATE   AVAILABLE   AGE
kube-system      deployment.apps/coredns                     1/1     1            1           8d
kube-system      deployment.apps/dashboard-metrics-scraper   1/1     1            1           8d
kube-system      deployment.apps/kubernetes-dashboard        1/1     1            1           8d
minio-operator   deployment.apps/console                     1/1     1            1           7d22h
kube-system      deployment.apps/hostpath-provisioner        1/1     1            1           7d22h
kube-system      deployment.apps/calico-kube-controllers     1/1     1            1           8d
kube-system      deployment.apps/metrics-server              1/1     1            1           8d
minio-operator   deployment.apps/minio-operator              1/2     2            1           7d22h

NAMESPACE        NAME                                                  DESIRED   CURRENT   READY   AGE
kube-system      replicaset.apps/coredns-6f5f9b5d74                    1         1         1       8d
kube-system      replicaset.apps/dashboard-metrics-scraper-7bc864c59   1         1         1       8d
kube-system      replicaset.apps/kubernetes-dashboard-dc96f9fc         1         1         1       8d
minio-operator   replicaset.apps/console-66c4b79fbd                    1         1         1       7d22h
kube-system      replicaset.apps/hostpath-provisioner-69cd9ff5b8       1         1         1       7d22h
kube-system      replicaset.apps/calico-kube-controllers-79568db7f8    1         1         1       8d
kube-system      replicaset.apps/metrics-server-6f754f88d              1         1         1       8d
minio-operator   replicaset.apps/minio-operator-67dcf6dd7c             2         2         1       7d22h

NAMESPACE        NAME                             READY   AGE
minio-operator   statefulset.apps/microk8s-ss-0   1/1     7d22h

I’ve tried the following commands to connect to the pod via the Python API, but keep getting errors:

client = Minio("microk8s-ss-0-0", secure=False)

try:
    objects = client.list_objects("bucket-1",prefix='/',recursive=True)
    for obj in objects:
        print (obj.bucket_name)
except InvalidResponseError as err:
    print (err)

And received the following error:

MaxRetryError: HTTPConnectionPool(host='microk8s-ss-0-0', port=80): Max retries exceeded with url: /bucket-1?delimiter=&encoding-type=url&list-type=2&max-keys=1000&prefix=%2F (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f29041e1e40>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

I also tried:
client = Minio("10.152.183.195", secure=False)

And got the same result. How do I access the minio pod from the API?

Asked By: Mark C

||

Answers:

Can you try this?

client = Minio("minio.minio-operator.svc.cluster.local:80", 
YOUR_ACCESS_KEY, YOUR_SECRET_KEY, secure=False)

If the service cannot be reached where your python code is running you can port-forward the service using the command below

microk8s kubectl -n minio-operator port-forward svc/minio 80

and then you can do

client = Minio("localhost:80", 
YOUR_ACCESS_KEY, YOUR_SECRET_KEY, secure=False)
Answered By: dilverse
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.