First release

This commit is contained in:
Adrien Reslinger 2020-03-16 15:34:32 +01:00
parent f9305cfab1
commit adca04dadf
13 changed files with 260 additions and 0 deletions

View file

@ -1,2 +1,3 @@
# ansible-role-k8s-storage
Deploy storage class to kubernetes cluster

6
bin/gen_list.sh Executable file
View file

@ -0,0 +1,6 @@
#!/bin/bash
wget https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml
kubernetes-split-yaml local-path-storage.yaml > generated.log
mv generated local
cat generated.log | while read LIGNE; do if [ $(echo "${LIGNE}" | grep -c ^File) -eq 1 ]; then echo -n "${LIGNE} "; else echo "${LIGNE}"; fi; done | grep ^File | sort -V | sed 's|.*\(generated/\)\(.*\.yaml\)| - "local/\2"|'
sed 's|/opt/local-path-provisioner|/mnt/shared|' -i local/local-path-config-ConfigMap.yaml

3
defaults/main.yml Normal file
View file

@ -0,0 +1,3 @@
my_context: flamykube
storage_localpath: true
storage_default_storageclass: local-path

View file

@ -0,0 +1,105 @@
apiVersion: v1
kind: Namespace
metadata:
name: local-path-storage
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: local-path-provisioner-service-account
namespace: local-path-storage
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: local-path-provisioner-role
rules:
- apiGroups: [""]
resources: ["nodes", "persistentvolumeclaims"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["endpoints", "persistentvolumes", "pods"]
verbs: ["*"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "patch"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: local-path-provisioner-bind
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: local-path-provisioner-role
subjects:
- kind: ServiceAccount
name: local-path-provisioner-service-account
namespace: local-path-storage
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: local-path-provisioner
namespace: local-path-storage
spec:
replicas: 1
selector:
matchLabels:
app: local-path-provisioner
template:
metadata:
labels:
app: local-path-provisioner
spec:
serviceAccountName: local-path-provisioner-service-account
containers:
- name: local-path-provisioner
image: rancher/local-path-provisioner:v0.0.12
imagePullPolicy: IfNotPresent
command:
- local-path-provisioner
- --debug
- start
- --config
- /etc/config/config.json
volumeMounts:
- name: config-volume
mountPath: /etc/config/
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
volumes:
- name: config-volume
configMap:
name: local-path-config
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local-path
provisioner: rancher.io/local-path
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
---
kind: ConfigMap
apiVersion: v1
metadata:
name: local-path-config
namespace: local-path-storage
data:
config.json: |-
{
"nodePathMap":[
{
"node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
"paths":["/opt/local-path-provisioner"]
}
]
}

View file

@ -0,0 +1,7 @@
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local-path
provisioner: rancher.io/local-path
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete

View file

@ -0,0 +1,16 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: local-path-config
namespace: local-path-storage
data:
config.json: |-
{
"nodePathMap":[
{
"node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
"paths":["/mnt/shared"]
}
]
}

View file

@ -0,0 +1,38 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: local-path-provisioner
namespace: local-path-storage
spec:
replicas: 1
selector:
matchLabels:
app: local-path-provisioner
template:
metadata:
labels:
app: local-path-provisioner
spec:
serviceAccountName: local-path-provisioner-service-account
containers:
- name: local-path-provisioner
image: rancher/local-path-provisioner:v0.0.12
imagePullPolicy: IfNotPresent
command:
- local-path-provisioner
- --debug
- start
- --config
- /etc/config/config.json
volumeMounts:
- name: config-volume
mountPath: /etc/config/
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
volumes:
- name: config-volume
configMap:
name: local-path-config

View file

@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: local-path-provisioner-bind
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: local-path-provisioner-role
subjects:
- kind: ServiceAccount
name: local-path-provisioner-service-account
namespace: local-path-storage

View file

@ -0,0 +1,17 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: local-path-provisioner-role
rules:
- apiGroups: [""]
resources: ["nodes", "persistentvolumeclaims"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["endpoints", "persistentvolumes", "pods"]
verbs: ["*"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "patch"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]

View file

@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: local-path-provisioner-service-account
namespace: local-path-storage

View file

@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: local-path-storage

7
meta/main.yml Normal file
View file

@ -0,0 +1,7 @@
galaxy_info:
author: Adrien Reslinger
description: Install storage class to a cluster
company: Flaminem
min_ansible_version: 2.9
galaxy_tags: []

39
tasks/main.yml Normal file
View file

@ -0,0 +1,39 @@
- name: Local Path setup
block:
- name: namespace
k8s:
context: "{{ my_context }}"
state: present
name: kubernetes-dashboard
api_version: v1
kind: Namespace
- name: dashboard install
k8s:
state: present
context: "{{ my_context }}"
resource_definition: "{{ lookup('file', item) | from_yaml }}"
with_items:
- "local/local-path-storage-Namespace.yaml"
- "local/local-path-provisioner-service-account-ServiceAccount.yaml"
- "local/local-path-provisioner-role-ClusterRole.yaml"
- "local/local-path-provisioner-bind-ClusterRoleBinding.yaml"
- "local/local-path-provisioner-Deployment.yaml"
- "local/local-path-StorageClass.yaml"
- "local/local-path-config-ConfigMap.yaml"
when:
- storage_localpath == true
- name: Select the default StorageClass
k8s:
state: present
context: "{{ my_context }}"
definition:
apiVersion: v1
kind: StorageClass
metadata:
name: "{{ storage_default_storageclass }}"
annotations:
storageclass.kubernetes.io/is-default-class: "true"
when:
- storage_default_storageclass is defined