- 컨ν μ΄λκ° μΈλΆ μ€ν 리μ§μ μμΈμ€νκ³ κ³΅μ νλ λ°©λ²
- ν¬λμ κ° μ»¨ν μ΄λμλ λΆλ¦¬λ νμΌ μμ€ν μ‘΄μ¬
- λ³Όλ₯¨μ ν¬λμ μ»΄ν¬λνΈμ΄λ©° ν¬λμ μ€νμ μν΄ μ μ
- λ 립μ μΈ μΏ λ²λ€ν°μ€ μ€λΈμ νΈκ° μλλ©°, μ€μ€λ‘ μμ±, μμ λΆκ°
- κ° μ»¨ν μ΄λμ νμΌ μμ€ν μ λ³Όλ₯¨μ λ§μ΄νΈνμ¬ μμ±
- λ³Όλ₯¨ μ’
λ₯
-
μμλ³Όλ₯¨
- EmptyDir : μΌμμ μΈ λ°μ΄ν° μ μ₯
apiVersion: v1 kind: Pod metadata: name: count spec: containers: - image: gasbugs/count name: html-generator volumeMounts: - name: html mountPath: /var/htdocs - image: httpd name: web-server volumeMounts: - name: html mountPath: /usr/local/apache2/htdocs readOnly: true ports: - containerPort: 80 protocol: TCP volumes: - name: html emptyDir: {}
-
λ‘컬볼λ₯¨
- hostpath : ν¬λμ νΈμ€νΈ λ
Έλμ νμΌ μμ€ν
μμ νμΌμ΄λ λλ ν 리λ₯Ό λ§μ΄νΈ
apiVersion: v1 kind: Pod metadata: name: hostpath-http spec: containers: - image: httpd name: web-server volumeMounts: - name: html mountPath: /usr/local/apache2/htdocs readOnly: true ports: - containerPort: 80 protocol: TCP volumes: - name: html hostPath: # νΈμ€νΈ ν¨μ€ path: /var/htdocs type: Directory
- hostpath : ν¬λμ νΈμ€νΈ λ
Έλμ νμΌ μμ€ν
μμ νμΌμ΄λ λλ ν 리λ₯Ό λ§μ΄νΈ
-
λ€νΈμν¬ λ³Όλ₯¨
- nfs : κΈ°μ‘΄ NFS 곡μ κ° ν¬λμ μ₯μ°©
-
ν΄λΌμ°λ μ’ μμ λ€νΈμν¬ λ³Όλ₯¨
- gcePersistentDis : κ΅¬κΈ μ»΄ν¨νΈμμ§ μꡬλμ€ν¬ λ§μ΄νΈ
# gcloud λμ€ν¬ μμ± gcloud compute disks create --size=10GiB --zone=asia-northeast3-a mongodb
apiVersion: v1 kind: Pod metadata: name: mongodb spec: containers: - image: mongo name: mongodb volumeMounts: - mountPath: /data/db name: mongodb volumes: - name: mongodb gcePersistentDisk: pdName: mongodb fsType: ext4
- awsEBS : μλ§μ‘΄ μꡬλμ€ν¬ λ§μ΄νΈ
- azureFile : μ μ μꡬλμ€ν¬ λ§μ΄νΈ
- gcePersistentDis : κ΅¬κΈ μ»΄ν¨νΈμμ§ μꡬλμ€ν¬ λ§μ΄νΈ
-
# NFS μλ² μ€μΉ
apt-get update
apt-get install nfs-common nfs-kernel-server portmap
# λλ ν 리 μμ±
mkdir /home/nfs
chmod 777 /home/nfs
# μμ
vim /etc/exports # /home/nfs 0.0.0.0μ μ μ
mount -t nfs <nfsμλ² IP>:/home/nfs /mnt
- PersistentVolume (PV)
- PersistentVolumeClaim (PVC)
apiVersion: v1
kind: Pod
metadata:
name: mongodb
spec:
containers:
- image: mongo
name: mongodb
volumeMounts:
- mountPath: /data/db
name: mongodb
volumes:
- name: mongodb
persistentVolumeClaim:
claimName: mongo-pvc
---
# PVC
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mongo-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: ""
---
# PV
apiVersion: v1
kind: PersistentVolume
metadata:
name: mongo-pv
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
- ReadOnlyMany
persistentVolumeReclaimPolicy: Retain # Retain(μ μ§), Delete(μΈλΆ μΈνλΌμ μ°κ΄λ μ€ν λ¦¬μ§ μμ° λͺ¨λ μ κ±°), Recycle(λ³ΌλΈμ λν μ€ν¬λ½μ μννκ³ μ ν΄λΌμμ λν΄ λ€μ μ¬μ©ν μ μμ)
gcePersistentDisk:
pdName: mongodb
fsType: ext4
- λμ νλ‘λΉμ λ : PVλ₯Ό μ§μ λ§λλ λμ μ¬μ©μκ° μνλ PV μ νμ μ ννλλ‘ μ€λΈμ νΈ μ μ κ°λ₯.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: storage
provisioner: kubernetes.io/gce-pd
parameters:
type: pd-ssd
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mongo-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: storage
---
apiVersion: v1
kind: Pod
metadata:
name: mongodb
spec:
containers:
- image: mongo
name: mongodb
volumeMounts:
- mountPath: /data/db
name: mongodb
volumes:
- name: mongodb
persistentVolumeClaim:
claimName: mongo-pvc
μ΄ν리μΌμ΄μ μ μνλ₯Ό μ μ₯νκ³ κ΄λ¦¬νλλ° μ¬μ©λλ μΏ λ²λ€ν°μ€ κ°μ²΄.
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- port: 80
name: web
clusterIP: None
selector:
app: nginx
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: nginx
serviceName: "nginx" # ν€λλ μ€ μλΉμ€λ₯Ό μ§μ νλ€.
replicas: 3 # by default is 1
template:
metadata:
labels:
app: nginx
spec:
terminationGracePeriodSeconds: 10 # κ°μ μ’
λ£κΉμ§ λκΈ°νλ μκ°
containers:
- name: nginx
image: k8s.gcr.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates: # PVC μ€μ μ μ μ₯νλ λΆλΆ
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "standard"
resources:
requests:
storage: 1Gi