Skip to content

Instantly share code, notes, and snippets.

@benclarkwood
Last active September 6, 2022 10:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save benclarkwood/77dea418bcac21a91d4a28e59b489af1 to your computer and use it in GitHub Desktop.
Save benclarkwood/77dea418bcac21a91d4a28e59b489af1 to your computer and use it in GitHub Desktop.
All the commands from the tutorial to spare your copy/paste functionality.

First things first

docker pull mesosphere/dcos-commons:latest

Intro

https://mesosphere.github.io/dcos-commons/

Developer Setup

Download template

git clone git@github.com:benclarkwood/mesoscon-tutorial.git

or

https://github.com/benclarkwood/mesoscon-tutorial.git

cd mesoscon-tutorial

Enter docker container

docker run -it -v $(pwd):/code -w /code mesosphere/dcos-commons:latest

AWS credentials

https://bit.ly/statefulshh

aws configure

DC/OS cluster setup

https://docs.google.com/document/d/1G8-CccBmmue4qfEDusoAT8cdE-1EVteWA5C5OIe5dXk/

dcos cluster setup <cluster-url>

Hello, world!

name: memcache
scheduler:
  user: nobody
pods:
  hello:
    count: 1
    tasks:
      server:
        goal: RUNNING
        cmd: echo "Hello, world!"
        cpus: 0.1
        memory: 256

Dev cycle

./build.sh aws

dcos package uninstall --yes memcache --app-id=<your name>

Memcache

name: memcache
scheduler:
  user: nobody
pods:
  cache:
    count: 3
    image: benclarkwood/memcached:0.0.2
    tasks:
      server:
        goal: RUNNING
        cmd: memcached
        cpus: 1.0
        memory: 1024

A note on reservations

name: memcache
scheduler:
  user: nobody
pods:
  cache:
    count: 3
    image: benclarkwood/memcached:0.0.2
    tasks:
      server:
        goal: RUNNING
        cmd: memcached -l $MESOS_CONTAINER_IP -p $MEMCACHE_PORT
        cpus: 1.0
        memory: 1024
        ports:
          memcache:
            port: 0 # random port
            env-key: MEMCACHE_PORT
            advertise: true

Try it out

dcos task exec -it cache-0-server /bin/bash

echo -e 'add my_key 0 300 11\r\nhello world\r' | nc -q 1 $MESOS_CONTAINER_IP $MEMCACHE_PORT

echo -e 'get my_key' | nc -q 1 $MESOS_CONTAINER_IP $MEMCACHE_PORT

Adding a template

name: memcache
scheduler:
  user: nobody
pods:
  cache:
    count: 3
    image: benclarkwood/memcached:0.0.2
    uris:
      - {{BOOTSTRAP_URI}}
    tasks:
      server:
        goal: RUNNING
        cmd: ./bootstrap && memcached $(cat memcached.conf)
        cpus: 1.0
        memory: 1024
        configs:
          memcache:
            template: {{CONFIG_TEMPLATE_PATH}}/memcached.conf
            dest: memcached.conf
        env:
          MEMORY_LIMIT: 1000
        ports:
          memcache:
            port: 0 # random port
            env-key: MEMCACHE_PORT
            advertise: true

touch src/main/dist/memcached.conf

# Be VERY verbose.
-vv

# Set the memory cap
-m {{MEMORY_LIMIT}}

# Set the TCP port
-p {{MEMCACHE_PORT}}

# Set the UDP port
-U {{MEMCACHE_PORT}}

# Specify which IP address to listen on. The default is to listen on all IP addresses
# This parameter is one of the only security measures that memcached has, so make sure
# it's listening on a firewalled interface.
-l {{MESOS_CONTAINER_IP}}
-l localhost

# Return error when memory is exhausted (rather than removing items)
-M

Sidecar plans

name: memcache
scheduler:
  user: nobody
pods:
  cache:
    count: 3
    image: benclarkwood/memcached:0.0.2
    volume:
      path: shared
      type: ROOT
      size: 64
    uris:
      - {{BOOTSTRAP_URI}}
    tasks:
      server:
        goal: RUNNING
        cmd: ./bootstrap && echo $MEMCACHE_PORT > shared/memcache-port && memcached $(cat memcached.conf)
        cpus: 1.0
        memory: 1024
        configs:
          memcache:
            template: {{CONFIG_TEMPLATE_PATH}}/memcached.conf
            dest: memcached.conf
        env:
          MEMORY_LIMIT: 1000
        ports:
          memcache:
            port: 0 # random port
            env-key: MEMCACHE_PORT
            advertise: true
      flush-cache:
        goal: FINISHED
        cmd: echo 'flush_all' | nc -q 10 localhost $(cat shared/memcache-port)
        cpus: 0.1
        memory: 32
plans:
  deploy:
    phases:
      cache:
        pod: cache
        steps:
          - default: [[server]]
  flush-all-serial:
    phases:
      flush:
        strategy: serial
        pod: cache
        steps:
          - default: [[flush-cache]]
  flush-all-parallel:
    phases:
      flush:
        strategy: parallel
        pod: cache
        steps:
          - default: [[flush-cache]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment