LoginSignup
19
18

More than 5 years have passed since last update.

kubernetes: pod(コンテナ)のディスク(volume)とパス(path)の指定方法

Last updated at Posted at 2016-02-28

コンテナを起動する際、dockerの場合はdocker runコマンドのオプションで色々指定できるが、kubernetesの場合は、pod(またはreplication controller)作成時に指定するyaml/jsonで規定する。

kubernetesでコンテナ(pod)を作成する際の、データの格納場所(volume)を指定する方法を記載する。
コンテナ(Pod)が死んでしまうと、データが消滅してしまうので、Volumeに格納しておく事で、状態を維持できる。
タイプは様々提供されている。

•emptyDir
•hostPath
•gcePersistentDisk
•awsElasticBlockStore
ほか

emptyDirは、Pod単位の仮想ボリュームで、Podがdeleteされると同時にデータも削除される。
hostPathは、ホストサーバ上のDiskにマウントする方式。ホストサーバ上のデータにアクセスしたい場合等に利用。
gcePersistentDiskは、Google Compute Engine (GCE) Persistent Disk をマウントする用。
awsElasticBlockStoreは、Amazon Web Services (AWS) EBS Volume をマウントする用。

Podに紐づけずデータを保持したい場合はhostPath等を指定する。

Pod yaml (EmptyDir) 例)

apiVersion: v1
kind: ReplicationController
metadata:
  name: redis
spec:
  template:
    metadata:
      labels:
        app: redis
        tier: backend
    spec:
      # Provision a fresh volume for the pod
      volumes:
        - name: data
          emptyDir: {}
      containers:
      - name: redis
        image: kubernetes/redis:v1
        ports:
        - containerPort: 6379
        # Mount the volume into the pod
        volumeMounts:
        - mountPath: /redis-master-data
          name: data   # must match the name of the volume, above

specの中にvolume:でタイプと名称を指定する。さらにcontainers:volumeMounts:で実際のPathを指定する。

参考
http://kubernetes.io/v1.1/docs/user-guide/volumes.html

19
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
18