Skip to content

Commit

Permalink
Containerise and add RBAC to deploy on k8s as deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
viveksinghggits committed Sep 12, 2021
1 parent 5bebcb2 commit 7b1f5ef
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM alpine

COPY kluster /usr/local/bin

ENTRYPOINT ["kluster"]
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"

Expand All @@ -27,7 +28,11 @@ func main() {

config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
log.Printf("Building config from flags, %s", err.Error())
log.Printf("Building config from flags failed, %s, trying to build inclusterconfig", err.Error())
config, err = rest.InClusterConfig()
if err != nil {
log.Printf("error %s building inclusterconfig", err.Error())
}
}

klientset, err := klient.NewForConfig(config)
Expand Down
31 changes: 31 additions & 0 deletions manifests/install/cr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: kluster-cr
rules:
- apiGroups:
- viveksingh.dev
resources:
- klusters
verbs:
- list
- watch
- apiGroups:
- ""
resources:
- events
verbs:
- create
- apiGroups:
- viveksingh.dev
resources:
- klusters/status
verbs:
- update
- apiGroups:
- viveksingh.dev
resources:
- klusters
verbs:
- get
13 changes: 13 additions & 0 deletions manifests/install/crb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
creationTimestamp: null
name: kluster-crb
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kluster-cr
subjects:
- kind: ServiceAccount
name: kluster-sa
namespace: default
25 changes: 25 additions & 0 deletions manifests/install/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: kluster
name: kluster
spec:
replicas: 1
selector:
matchLabels:
app: kluster
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: kluster
spec:
containers:
- image: viveksinghggits/kluster:0.1.0
name: kluster
resources: {}
serviceAccountName: kluster-sa
status: {}
12 changes: 12 additions & 0 deletions manifests/install/krole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
creationTimestamp: null
name: k-role
rules:
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
13 changes: 13 additions & 0 deletions manifests/install/kroleb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
creationTimestamp: null
name: k-rb
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: k-role
subjects:
- kind: ServiceAccount
name: kluster-sa
namespace: default
5 changes: 5 additions & 0 deletions manifests/install/sa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
creationTimestamp: null
name: kluster-sa
2 changes: 1 addition & 1 deletion manifests/klusterone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
spec:
name: kluster-0
region: "nyc1"
version: "1.21.2-do.2"
version: "1.21.3-do.0"
tokenSecret: "default/dosecret"
nodePools:
- count: 3
Expand Down
2 changes: 1 addition & 1 deletion manifests/klustertwo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
spec:
name: kluster-1
region: "nyc1"
version: "1.21.2-do.2"
version: "1.21.3-do.0"
tokenSecret: "default/dosecret"
nodePools:
- count: 3
Expand Down

0 comments on commit 7b1f5ef

Please sign in to comment.