iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 15
0
DevOps

Cloud Native 開發維運一條龍系列 第 15

Day 15. Kubernetes Volume 基本操作

今天來設定 k8s 裡的 volume, k8s 有三個抽象

  • runtime
  • network
  • volume

runtime 我們通常都選 docker ,就算有其他選擇像是 rkt、OCI(Open Container Initiative),但都比較非主流; network 的選擇也有限,常用的選擇像是 flannel 、 calico…等等,而 PersistentVolume 與 PersistenVolumeClaim 相對就比較百花齊放。

這邊只介紹一種簡單的。

create pv.yaml

kind: PersistentVolume
apiVersion: v1
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"

create pvc.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: task-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi

create pod.yaml

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

Helm

$ 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

Play with Helm

$ helm install stable/prometheus-operator --name prometheus-operator --namespace monitoring

ref


上一篇
Day 14. Kubernetes Network 基本操作
下一篇
Day 16. The Three Ways - Flow
系列文
Cloud Native 開發維運一條龍18
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言