[쿠버네티스 스토리지] GCE 디스크를 활용한 네트워크 볼륨 연결

hi·2023년 8월 1일
0

쿠버네티스

목록 보기
41/60

GCE 영구 스토리지 사용하기

  • 데이터가 지속
  • 모든 파드에서 공유
  • mongo 컨테이너에 마운트하여 사용

  • GCE 영구 디스트를 동일한 리전에 생성
    gcloud compute disks create --size=10GiB --zone=us-central1-c mongodb
imkunyoung@master-1:~/volume$ gcloud compute disks create --size=10GiB --zone=us-central1-a mongodb
WARNING: You have selected a disk size of under [200GB]. This may result in poor I/O performance. For more information, see: https://developers.google.com/compute/docs/disks#performance.
Created [https://www.googleapis.com/compute/v1/projects/k8s-inflearn/zones/us-central1-a/disks/mongodb].
NAME     ZONE           SIZE_GB  TYPE         STATUS
mongodb  us-central1-a  10       pd-standard  READY

New disks are unformatted. You must format and mount a disk before it
can be used. You can find instructions on how to do this at:

https://cloud.google.com/compute/docs/disks/add-persistent-disk#formatting



To take a quick anonymous survey, run:
  $ gcloud survey

  • 파드 YAML의 gcePersistentDisk 정의하기
    - 볼륨만을 별도로 선언할 수 없기 때문에 파드를 생성하여 volume 구성

mongo-pod-gce.yaml

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: mongodb
  name: mongodb
spec:
  volumes:
    - name: mongodb-data
      gcePersistentDisk:
        pdName: mongodb
        fsType: ext4
  containers:
    - image: mongo
      name: mongodb
      volumeMounts:
        - mountPath: /data/db
          name: mongodb-data
      ports:
        - containerPort: 27017
          protocol: TCP
status: { }

볼륨에는 mongo-data를 선언하고 gce 디스크를 사용 정의 "pdName"의 명칭은 앞서 생성한 디스크의 이름과 동일해야 함




imkunyoung@cloudshell:~/storage (k8s-inflearn)$ kubectl create -f mongodb.yaml
pod/mongodb created

imkunyoung@cloudshell:~/storage (k8s-inflearn)$ kubectl get pods 
NAME      READY   STATUS    RESTARTS   AGE
mongodb   1/1     Running   0          12s
imkunyoung@cloudshell:~/storage (k8s-inflearn)$ kubectl describe pod mongodb
Name:             mongodb
Namespace:        default
Priority:         0
Service Account:  default
Node:             gke-my-first-cluster-1-default-pool-a0f2cf43-uu79/10.128.0.9
Start Time:       Sun, 20 Aug 2023 16:57:24 +0000
Labels:           run=mongodb
Annotations:      <none>
Status:           Running
IP:               10.104.0.52
IPs:
  IP:  10.104.0.52
Containers:
  mongodb:
    Container ID:   containerd://b7fa107df83faa846310791036b94b68e8344e8c44df87be7af77ef9c9b3ca83
    Image:          mongo
    Image ID:       docker.io/library/mongo@sha256:a89d79ddc5187f57b1270f87ec581b7cc6fd697efa12b8f1af72f3c4888d72b5
    Port:           27017/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Sun, 20 Aug 2023 16:57:30 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /data/db from mongodb-data (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-pkqw9 (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  mongodb-data:
    Type:       GCEPersistentDisk (a Persistent Disk resource in Google Compute Engine)
    PDName:     mongodb
    FSType:     ext4
    Partition:  0
    ReadOnly:   false
  kube-api-access-pkqw9:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason                  Age   From                     Message
  ----    ------                  ----  ----                     -------
  Normal  Scheduled               96s   default-scheduler        Successfully assigned default/mongodb to gke-my-first-cluster-1-default-pool-a0f2cf43-uu79
  Normal  SuccessfulAttachVolume  92s   attachdetach-controller  AttachVolume.Attach succeeded for volume "pd.csi.storage.gke.io-mongodb"
  Normal  Pulling                 91s   kubelet                  Pulling image "mongo"
  Normal  Pulled                  90s   kubelet                  Successfully pulled image "mongo" in 430.97483ms (430.992992ms including waiting)
  Normal  Created                 90s   kubelet                  Created container mongodb
  Normal  Started                 90s   kubelet                  Started container mongodb


imkunyoung@cloudshell:~/storage (k8s-inflearn)$ kubectl exec -it mongodb -- mongosh
Current Mongosh Log ID: 64e24704d55cdec56609311e
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.10.5
Using MongoDB:          7.0.0
Using Mongosh:          1.10.5

For mongosh info see: https://docs.mongodb.com/mongodb-shell/


To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.

------
   The server generated these startup warnings when booting
   2023-08-20T16:57:30.330+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
   2023-08-20T16:57:31.158+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2023-08-20T16:57:31.159+00:00: vm.max_map_count is too low
------

test> use mystore
switched to db mystore
mystore> db.foo.insert({name:'test', value:'1234'})
DeprecationWarning: Collection.insert() is deprecated. Use insertOne, insertMany, or bulkWrite.
{
  acknowledged: true,
  insertedIds: { '0': ObjectId("64e24753d55cdec56609311f") }
}
mystore> db.foo.find({name:'test', value:'1234'})
[
  {
    _id: ObjectId("64e24753d55cdec56609311f"),
    name: 'test',
    value: '1234'
  }
]
mystore> 
imkunyoung@cloudshell:~/storage (k8s-inflearn)$ kubectl delete pod mongodb
pod "mongodb" deleted




imkunyoung@cloudshell:~/storage (k8s-inflearn)$ kubectl create -f mongodb.yaml
pod/mongodb created
imkunyoung@cloudshell:~/storage (k8s-inflearn)$ ls
mongodb.yaml
imkunyoung@cloudshell:~/storage (k8s-inflearn)$ kubectl get pod
NAME      READY   STATUS    RESTARTS   AGE
mongodb   1/1     Running   0          12s

imkunyoung@cloudshell:~/storage (k8s-inflearn)$ kubectl exec -it mongodb -- mongosh 
Current Mongosh Log ID: 64e24927b8d530a9d6fd2451
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.10.5
Using MongoDB:          7.0.0
Using Mongosh:          1.10.5

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

------
   The server generated these startup warnings when booting
   2023-08-20T17:07:53.968+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
   2023-08-20T17:07:55.346+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2023-08-20T17:07:55.346+00:00: vm.max_map_count is too low
------

test> db.foo.find({name:'test', value:'1234'})

test> use mystore
switched to db mystore
mystore> db.foo.find({name:'test', value:'1234'})
[
  {
    _id: ObjectId("64e24753d55cdec56609311f"),
    name: 'test',
    value: '1234'
  }
]
mystore> 

0개의 댓글