今天來設定 k8s 裡的 volume, k8s 有三個抽象
runtime 我們通常都選 docker ,就算有其他選擇像是 rkt、OCI(Open Container Initiative),但都比較非主流; network 的選擇也有限,常用的選擇像是 flannel 、 calico…等等,而 PersistentVolume 與 PersistenVolumeClaim 相對就比較百花齊放。
這邊只介紹一種簡單的。
kind: PersistentVolume
apiVersion: v1
metadata:
name: task-pv-volume
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: task-pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
kind: Pod
apiVersion: v1
metadata:
name: task-pv-pod
spec:
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: task-pv-claim
containers:
- name: task-pv-container
image: nginx
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: task-pv-storage
$ wget https://bit.ly/2IIn5WW
$ tar -xvf 2IIn5WW
$ sudo cp linux-amd64/helm /usr/local/bin/
$ kubectl create serviceaccount --namespace kube-system tiller
$ kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
$ helm init
$ kubectl -n kube-system patch deployment tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
$ helm init --upgrade
$ helm install stable/prometheus-operator --name prometheus-operator --namespace monitoring