Skip to content

Commit

Permalink
Initial Commit (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
nitisht authored and harshavardhana committed Oct 26, 2018
1 parent 15c26b7 commit 6b8c960
Show file tree
Hide file tree
Showing 1,576 changed files with 584,395 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
minio-operator
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:1.10.1-alpine3.7

LABEL maintainer="Minio Inc <dev@minio.io>"

WORKDIR /go/src/github.com/minio/
COPY . /go/src/github.com/minio/minio-operator

RUN \
apk add --no-cache ca-certificates 'curl>7.61.0' && \
cd /go/src/github.com/minio/minio-operator && \
go install

CMD ["minio-operator"]
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Minio Operator Guide

[![Slack](https://slack.minio.io/slack?type=svg)](https://slack.minio.io) [![Docker Pulls](https://img.shields.io/docker/pulls/minio/minio.svg?maxAge=604800)](https://hub.docker.com/r/minio/minio/)

Minio is a high performance distributed object storage server, designed for large-scale private cloud infrastructure. Minio is designed in a cloud-native manner to scale sustainably in multi-tenant environments. Orchestration platforms like Kubernetes provide perfect launchpad for Minio to scale. There are multiple options to deploy Minio on Kubernetes:

- Helm Chart: Minio Helm Chart offers customizable and easy Minio deployment with a single command. Refer [Minio Helm Chart repository documentation](https://github.com/helm/charts/tree/master/stable/minio) for more details.

- YAML File: Minio can be deployed with yaml files via kubectl. Refer [Minio yaml file documentation](https://docs.minio.io/docs/deploy-minio-on-kubernetes.html) to deploy Minio using yaml files.

- Minio-Operator: Operator creates and manages distributed Minio deployments running on Kubernetes, using CustomResourceDefinitions and Controller.

## Getting Started

### Prerequisites

- Kubernetes cluster 1.8.0+.
- `kubectl` configured to refer to relevant Kubernetes cluster.

### Create Operator and related resources

To start Minio-Operator, use the `docs/minio-operator.yaml` file.

```
kubectl create -f https://github.com/minio/minio-operator/blob/master/docs/minio-stanoperator.yaml?raw=true
```

This will create all relevant resources required for the Operator to work. Here is a list of resources created by above `yaml` file:

- `Namespace`: Custom namespace for Minio-Operator. By default it is names as `minio-operator-ns`.
- `CustomResourceDefinition`: Custom resource definition named as `minioinstances.miniocontroller.minio.io`.
- `ClusterRole`: A cluster wide role for the controller. It is named as `minio-operator-role`. This is used for RBAC.
- `ServiceAccount`: Service account is used by the custom controller to access the cluster. Account name by default is `minio-operator-sa`.
- `ClusterRoleBinding`: This cluster wide binding binds the service account `minio-operator-sa` to cluster role `minio-operator-role`.
- `Deployment`: Deployment creates a pod using the Minio-Operator Docker image. This is where the custom controller runs and looks after any changes in custom resource.

### Create a Minio instance

Once Minio-Operator deployment is running, you can create Minio instances using the below command

```
kubectl create -f https://github.com/minio/minio-operator/blob/master/docs/minio-examples/minio-secret.yaml?raw=true
kubectl create -f https://github.com/minio/minio-operator/blob/master/docs/minio-examples/minioinstance.yaml?raw=true
```

## Features

Minio-Operator currently supports following features:

- Create and delete highly available distributed Minio clusters.
- Upgrading existing distributed Minio clusters.

## Upcoming features

With next release, we'll add Minio cluster mirror option based on [mc mirror](https://docs.minio.io/docs/minio-client-complete-guide.html#mirror) command.

## Explore Further

- [Minio Erasure Code QuickStart Guide](https://docs.minio.io/docs/minio-erasure-code-quickstart-guide)
- [Use `mc` with Minio Server](https://docs.minio.io/docs/minio-client-quickstart-guide)
- [Use `aws-cli` with Minio Server](https://docs.minio.io/docs/aws-cli-with-minio)
- [The Minio documentation website](https://docs.minio.io)
12 changes: 12 additions & 0 deletions docs/crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: minioinstances.miniocontroller.minio.io
spec:
group: miniocontroller.minio.io
version: v1beta1
names:
kind: MinioInstance
plural: minioinstances
scope: Namespaced

8 changes: 8 additions & 0 deletions docs/minio-examples/minio-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: minio-creds-secret
type: Opaque
data:
accesskey: bWluaW8= # base 64 encoded "minio" (echo -n 'minio' | base64)
secretkey: bWluaW8xMjM= # based 64 encoded "minio123" (echo -n 'minio123' | base64)
17 changes: 17 additions & 0 deletions docs/minio-examples/minioinstance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: miniocontroller.minio.io/v1beta1
kind: MinioInstance
metadata:
name: minio
spec:
replicas: 4
credsSecret:
name: minio-creds-secret
volumeClaimTemplate:
metadata:
name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
93 changes: 93 additions & 0 deletions docs/minio-operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
apiVersion: v1
kind: Namespace
metadata:
name: minio-operator-ns
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: minioinstances.miniocontroller.minio.io
spec:
group: miniocontroller.minio.io
version: v1beta1
names:
kind: MinioInstance
plural: minioinstances
scope: Namespaced
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: minio-operator-role
rules:
- apiGroups:
- ""
resources:
- namespaces
- secrets
- pods
- services
verbs:
- get
- watch
- create
- list
- apiGroups:
- apps
resources:
- statefulsets
verbs:
- get
- create
- list
- patch
- apiGroups:
- miniocontroller.minio.io
resources:
- "*"
verbs:
- "*"
- apiGroups:
- minio.io
resources:
- "*"
verbs:
- "*"
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: minio-operator-sa
namespace: minio-operator-ns
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: minio-operator-binding
namespace: minio-operator-ns
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: minio-operator-role
subjects:
- kind: ServiceAccount
name: minio-operator-sa
namespace: minio-operator-ns
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: minio-operator
namespace: minio-operator-ns
spec:
replicas: 1
template:
metadata:
labels:
app: minio-operator
spec:
serviceAccountName: minio-operator-sa
containers:
- name: minio-operator
image: nitishtiwari/operator:2
---
112 changes: 112 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Minio-Operator - Manage Minio clusters in Kubernetes
*
* Minio (C) 2018 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"flag"
"os"
"os/signal"
"syscall"
"time"

"github.com/golang/glog"

kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"

clientset "github.com/minio/minio-operator/pkg/client/clientset/versioned"
informers "github.com/minio/minio-operator/pkg/client/informers/externalversions"
"github.com/minio/minio-operator/pkg/controller/cluster"
)

var masterURL string
var kubeconfig string
var onlyOneSignalHandler = make(chan struct{})
var shutdownSignals = []os.Signal{os.Interrupt, syscall.SIGTERM}

func init() {
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
flag.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
}

func main() {
// set up signals so we handle the first shutdown signal gracefully
stopCh := setupSignalHandler()

flag.Parse()

// Look for incluster config by default
cfg, err := rest.InClusterConfig()
// If config is passed as a flag use that instead
if kubeconfig != "" {
cfg, err = clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
}

if err != nil {
glog.Fatalf("Error building kubeconfig: %s", err.Error())
}

kubeClient, err := kubernetes.NewForConfig(cfg)
if err != nil {
glog.Fatalf("Error building kubernetes clientset: %s", err.Error())
}

controllerClient, err := clientset.NewForConfig(cfg)
if err != nil {
glog.Fatalf("Error building example clientset: %s", err.Error())
}

kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, time.Second*30)
minioInformerFactory := informers.NewSharedInformerFactory(controllerClient, time.Second*30)

controller := cluster.NewController(kubeClient, controllerClient,
kubeInformerFactory.Apps().V1().StatefulSets(),
minioInformerFactory.Minio().V1beta1().MinioInstances(),
kubeInformerFactory.Core().V1().Services())

go kubeInformerFactory.Start(stopCh)
go minioInformerFactory.Start(stopCh)

if err = controller.Run(2, stopCh); err != nil {
glog.Fatalf("Error running controller: %s", err.Error())
}
}

// setupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned
// which is closed on one of these signals. If a second signal is caught, the program
// is terminated with exit code 1.
func setupSignalHandler() (stopCh <-chan struct{}) {
// panics when called twice
close(onlyOneSignalHandler)

stop := make(chan struct{})
c := make(chan os.Signal, 2)
signal.Notify(c, shutdownSignals...)
go func() {
<-c
close(stop)
<-c
// second signal. Exit directly.
os.Exit(1)
}()

return stop
}
23 changes: 23 additions & 0 deletions pkg/apis/miniocontroller/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Minio-Operator - Manage Minio clusters in Kubernetes
*
* Minio (C) 2018 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package miniocontroller

const (
GroupName = "miniocontroller.minio.io"
)
23 changes: 23 additions & 0 deletions pkg/apis/miniocontroller/v1beta1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Minio-Operator - Manage Minio clusters in Kubernetes
*
* Minio (C) 2018 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// +k8s:deepcopy-gen=package

// Package v1beta1 is the v1beta1 version of the API.
// +groupName=minio.io.io
package v1beta1
Loading

0 comments on commit 6b8c960

Please sign in to comment.