Skip to content

Commit

Permalink
setup_minio: add variable to specify service type (#45)
Browse files Browse the repository at this point in the history
* setup_minio: add variable to specify service type and default to NodePort
  • Loading branch information
manurodriguez authored Nov 17, 2023
1 parent 6e0e0c7 commit 932c125
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 57 deletions.
47 changes: 35 additions & 12 deletions roles/setup_minio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ Role tasks:

## Variables

| Variable | Default | Required | Description |
| -------------------------------------- | ----------------------------- | ---------- | ----------------------------------------------|
| sm_minio_image | minio/minio | No | Default Minio image |
| sm_claim_size | 10Gi | No | Requested storage for Minio |
| sm_storage_class | undefined | Yes | A storage Class with Support for RWX volumes |
| sm_namespace | minio | No | Deployment Namespace |
| sm_access_key_id | minioadmin | No | Minio's Initial Username |
| sm_access_key_secret | minioadmin | No | Minio's Initial Password |
| sm_bucket_name | minio | No | Initial Bucket name |
| sm_action | install | No | Default role's action |
| Variable | Default | Required | Description |
| -------------------------------------- | ----------------------------- | ---------- | ----------------------------------------------------|
| sm_minio_image | minio/minio | No | Default Minio image |
| sm_claim_size | 10Gi | No | Requested storage for Minio |
| sm_storage_class | undefined | Yes | A storage Class with Support for RWX volumes |
| sm_namespace | minio | No | Deployment Namespace |
| sm_access_key_id | minioadmin | No | Minio's Initial Username |
| sm_access_key_secret | minioadmin | No | Minio's Initial Password |
| sm_bucket_name | minio | No | Initial Bucket name |
| sm_action | install | No | Default role's action |
| sm_service_type | NodePort | No | Type of service: NodePort, LoadBalacer or ClusterIP |

## Role requirements
- A storage class with Support for ReadWriteMany volumes. NFS based providers are suitable for this. The PVC bound will fail if RWX mode is not supported.
- 10Gi available in the defined StorageClass
- When enabling the service to use a external IP (`sm_service_type: LoadBalacer`) MetalLB operator is required to be installed and configured in the cluster.

## Usage example

Expand Down Expand Up @@ -55,11 +57,32 @@ See below how to consume the services provided by Minio.
## From outside the cluster:
Get the node port assigned to the Kubernetes service. In the command shown below it is 31551
### When using LoadBalacer service type
> NOTE: The variable `sm_service_type: LoadBalacer` is required to enable external access to the service.

Get the external IP assigned and port to the Kubernetes service. In the command shown below is 10.20.30.40:9000
```
$ oc get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
minio-service LoadBalancer 172.30.108.47 <pending> 9000:31551/TCP 28m
minio-service LoadBalancer 172.30.108.47 10.20.30.40 9000:31203/TCP 28m
```
Use the endpoint to connect:
- http://\<external-ip\>:\<port\>
### When using NodePort service type (default)
Get a node IP and the node port assigned to the Kubernetes service. In the command shown below it is 192.168.X.Y and 30521
```
$ oc get nodes -o custom-columns=INTERNAL-IP:status.addresses[0].address

INTERNAL-IP
192.168.X.Y
...

$ oc get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
minio-service NodePort 172.30.251.192 <none> 9000:30521/TCP 8s
```
Use the endpoint to connect:
Expand Down
1 change: 1 addition & 0 deletions roles/setup_minio/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ sm_access_key_secret: minioadmin
sm_bucket_name: minio
sm_action: install
sm_minio_image: quay.io/minio/minio:latest
sm_service_type: NodePort
...
93 changes: 48 additions & 45 deletions roles/setup_minio/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
name: "{{ service_name }}"
namespace: "{{ sm_namespace }}"
spec:
type: LoadBalancer
type: "{{ sm_service_type }}"
ports:
- name: http
port: 9000
Expand All @@ -124,51 +124,54 @@
- "node-role.kubernetes.io/worker"
register: node_info

- name: Check minio service availability
vars:
random_worker_ip: "{{ node_info.resources | json_query('[].status.addresses[?type==`InternalIP`].address') | random | first }}"
node_port: "{{ service_info.resources[0].spec.ports[0].nodePort }}"
uri:
url: "http://{{ random_worker_ip }}:{{ node_port }}/minio/health/ready"
return_content: no
status_code: 200
register: response
retries: 50
delay: 5
until: response.status == 200
- name: Validate minio service using NodePort
block:
- name: Check minio service availability
vars:
random_worker_ip: "{{ node_info.resources | json_query('[].status.addresses[?type==`InternalIP`].address') | random | first }}"
node_port: "{{ service_info.resources[0].spec.ports[0].nodePort }}"
uri:
url: "http://{{ random_worker_ip }}:{{ node_port }}/minio/health/ready"
return_content: no
status_code: 200
register: response
retries: 50
delay: 5
until: response.status == 200

- name: Create working directory
tempfile:
state: directory
prefix: minio_
register: minio_dir
- name: Create working directory
tempfile:
state: directory
prefix: minio_
register: minio_dir

- name: Set working directory path
set_fact:
minio_dir: "{{ minio_dir.path }}"
- name: Set working directory path
set_fact:
minio_dir: "{{ minio_dir.path }}"

- name: Get Minio CLI
vars:
minio_cli: "https://dl.min.io/client/mc/release/linux-amd64/mc"
get_url:
url: "{{ minio_cli }}"
dest: "{{ minio_dir }}/"
mode: "0750"
- name: Get Minio CLI
vars:
minio_cli: "https://dl.min.io/client/mc/release/linux-amd64/mc"
get_url:
url: "{{ minio_cli }}"
dest: "{{ minio_dir }}/"
mode: "0750"

- name: Create an initial bucket
vars:
random_worker_ip: "{{ node_info.resources | json_query('[].status.addresses[?type==`InternalIP`].address') | random | first }}"
node_port: "{{ service_info.resources[0].spec.ports[0].nodePort }}"
instance: local
shell: |
{{ minio_dir }}/mc alias set {{ instance }} \
http://{{ random_worker_ip }}:{{ node_port }} \
{{ sm_access_key_id }} {{ sm_access_key_secret }} --api S3v4;
{{ minio_dir }}/mc mb --ignore-existing {{ instance }}/{{ sm_bucket_name }}
register: minio_cmd
retries: 18
delay: 5
until: minio_cmd is not failed
notify:
- "Delete temp directory"
...
- name: Create an initial bucket
vars:
random_worker_ip: "{{ node_info.resources | json_query('[].status.addresses[?type==`InternalIP`].address') | random | first }}"
node_port: "{{ service_info.resources[0].spec.ports[0].nodePort }}"
instance: local
shell: |
{{ minio_dir }}/mc alias set {{ instance }} \
http://{{ random_worker_ip }}:{{ node_port }} \
{{ sm_access_key_id }} {{ sm_access_key_secret }} --api S3v4;
{{ minio_dir }}/mc mb --ignore-existing {{ instance }}/{{ sm_bucket_name }}
register: minio_cmd
retries: 18
delay: 5
until: minio_cmd is not failed
notify:
- "Delete temp directory"
when: sm_service_type == "NodePort"
...

0 comments on commit 932c125

Please sign in to comment.