Skip to content

Latest commit

 

History

History
122 lines (72 loc) · 3.54 KB

Storage.md

File metadata and controls

122 lines (72 loc) · 3.54 KB

Storage

When using Docker Volumes, the built-in local diver or a third-party dirver can be used.Docker volumes are managed by Docker and a directory is created in /var/lib/docker/volumes on the container instance that contains the volume data.

We're focusing on built-in local dirver and third-party driver to setup data volume for in task. If you want to use bind mounts, here's more

Playbook

1. Prepare enviroment

Note: You can ignore this step if you finished previous module - Using spot instance as worker nodes without clean-up!!!

# setup variables
cd ecs-mesh-workshop/bin;
# modify environments in ./bashrc.ext
source ./bashrc.ext

# quick deployment, setup infrastructure & standup ECS cluster with on-demand instance
./install_all.sh spot

2. Local driver

A directory is created in /var/lib/docker/volumes on the container instance that contains the volume data.

cd ecs-mesh-workshop/template/storage

# create a volume on worker node.
docker run -ti --volume-driver=local -v test-local:/test-local busybox
df -h /test-local

# check out folder /var/lib/docker/volumes
ls /var/lib/docker/volumes

3. REX-Ray

Creat a policy and attach to instnace role of worker nodes.

cd ecs-mesh-workshop/template/storage

aws iam create-policy --policy-name rexray-ecs-policy --policy-document file://rexray-iam-policy.json

Register task to test local volume.

aws ecs register-task-definition --cli-input-json file://mysql-local-task-definition.json
aws ecs run-task --cluster $ECS_CLUSTER_NAME --task-definition mysql-local --count 1

Install Rex-Ray driver on each worker nodes.

# list public IP addresses in order to login and install dirver
aws ec2 describe-instances --filters "Name=tag:Owner,Values=CC,Name=availability-zone,Values=us-west-2b"| jq '.Reservations[].Instances[].PublicIpAddress'

# install rexray dirver
docker plugin install rexray/ebs REXRAY_PREEMPT=true EBS_REGION=$AWS_REGION --grant-all-permissions

# if driver is not active and then restart the container agent
sudo systemctl restart ecs

# check it out after install
docker plugin ls
docker run -ti --volume-driver=rexray/ebs -v test-rexray:/test-rexray busybox
df -h /test

# Check out EBS volume
aws ec2 describe-volumes --filters "Name=tag:Name,Values=test-rexray"

Register task to test volume by REX-Ray.

aws ecs register-task-definition --cli-input-json file://mysql-rexray-task-definition.json
aws ecs run-task --cluster $ECS_CLUSTER_NAME --task-definition mysql-rexray --count 1

With REX-Ray, it's also work with other storages, such as EFS and S3, check out here.

6. Clean-up

# delete all stacks in CloudFormation
cd ecs-mesh-workshop/bin
./clean_up.sh

# manually delete EBS volume
aws ec2 describe-volumes --filters "Name=tag:Name,Values=test-rexray"
aws ec2 delete-volume --volume-id <VolumeId>
aws ec2 describe-volumes --filters "Name=tag:Name,Values=rexray-vol"
aws ec2 delete-volume --volume-id <VolumeId>

Resources

Using data volumes in Task

REX-Ray

REX-Ray for EBS

REX-Ray for EFS