...
- Mount the CoreOS image within the virtual machine 'CoreOS <version> - cluster-r730-1'
- Run the virtual machine
Create a new user (mandatory) and install CoreOS
Code Block language bash title Listing 1 linenumbers true # create password hash (SSH key) ssh_key=´sudo openssl passwd -1´ # specify user information cat > cloud-config-file <<- EOF #cloud-config users: - name: root passwd: ${ssh_key} groups: - sudo - docker EOF # install coreos to /dev/sda sudo coreos-install -d /dev/sda -C stable -c cloud-config-file
- Repeat the above steps for the virtual machine 'CoreOS <version> - cluster-r730-k20-1'
Step 3: Download Docker images
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
docker pull swarm docker pull progrium/consul docker pull hello-world |
Step 4: Setup local network
...
- Run the virtual machine 'CoreOS <version> - cluster-r730-1'
Setup the test scenario script
Code Block language bash title Listing 6 linenumbers true sudo cat > ~/docker-swarm-master-consul-demo.sh <<- EOF #!/bin/bash # docker-swarm-master-consul-demo.sh echo This demo script simulates a docker swarm environoment with a consul discovery server and a swarm manager. echo STEP 1: Clean up existing docker containers. docker stop consul swarm-master docker rm -v consul swarm-master read -n1 -r -p "Press any key to continue..." key echo STEP 2: Run the consul server as a new docker container. echo The following ports are published: echo 8400: RPC \(optional\) echo 8500: HTTP echo 8600: DNS \(optional\) docker run -d -p 8400:8400 -p 8500:8500 -p 8600:53/udp --name=consul --add-host=cluster-r730-1:192.168.0.15 --add-host=cluster-r730-k20-1:192.168.0.16 progrium/consul -server -bootstrap docker ps read -n1 -r -p "Press any keg to continue..." keg echo STEP 3: Run the swarm manager as a new docker container. echo The following ports are published: echo 4000: RPC docker run -d -p 4000:4000 --name=swarm-master --add-host=cluster-r730-1:192.168.0.15 --add-host=cluster-r730-k20-1:192.168.0.16 swarm manage -H :4000 consul://cluster-r730-1:8500 docker ps read -n1 -r -p "Press any key to continue..." key echo STEP 4: Check as port 4000 and 8500 are published. netstat -npl | grep '4000\|8500' read -n1 -r -p "Press any key to continue..." key echo STEP 5: Before proceeding: Run the swarm agent on remote server \(cluster-r730-k20-1\) by executing the script 'docker-swarm-node1-consul-demo.sh'. read -n1 -r -p "Press any key to continue..." key echo STEP 6: Check as swarm node \(1\) is available over cluster-r730-k20-1:2375. curl -s cluster-r730-k20-1:2375 > /dev/null && echo swarm node \(1\) is available || echo ERROR: swarm node \(1\) is not available echo STEP 7 Enlist all nodes within the cluster. docker run --rm --add-host=cluster-r730-1:192.168.0.15 --add-host=cluster-r730-k20-1:192.168.0.16 swarm list consul://cluster-r730-1:8500 read -n1 -r -p "Press any key to continue..." key echo STEP 8: Use regular docker commands on the swarm cluster. docker -H cluster-r730-1:4000 info echo End of the script. EOF
- Run the virtual machine 'CoreOS <version> - cluster-r730-k20-1'
Setup the test scenario script
Code Block language bash title Listing 7 linenumbers true sudo cat > ~/docker-swarm-node1-consul-demo.sh <<- EOF #!/bin/bash # docker—swarm—node1—consul—demodocker-swarm-node1-consul-demo.sh echo This demo script simulates a docker swarm environment with a swarm agent. echo STEP 1: Clean up existing docker containers. docker stop swarm—node—1swarm-node-1 docker rm —v swarm—node—1-v swarm-node-1 read —n1-n1 —r-r —p-p "Press any key to continue..." key echo STEP 2: Before proceeding: Run the consul server and swarm master on remote server \(cluster—r730—1cluster-r730-1\) by executing the script 'docker—swarm—master—consul—demodocker-swarm-master-consul-demo.sh'. read —n1-n1 —r-r —p-p "Press any key to continue..." key echo STEP 3: Check as the consul server and swarm manager are available over cluster—r730—1cluster-r730-1:[4000,8500]. curl —s cluster—r730—1-s cluster-r730-1:8500 > /deu/null && echo consul server is available || echo ERROR: consul server is not available curl —s-s cluster—r730—1cluster-r730-1:4000 > /deu/null && echo swarm master is available || echo ERROR: swarm master is not available read —n1-n1 —r-r —p-p "Press any key to continue..." key cho STEP 4: Run the swarm agent as a new docker container. echo echo The following ports are published: echo echo 2375: RPC docker run —d ——name swarm—node—1 ——add—host=cluster—r730—1-d --name swarm-node-1 --add-host=cluster-r730-1:192.168.0.15 ——add--add-host=cluster—r730—k20—1cluster-r730-k20-1:192.168.0.16 swarm join ——advertise=cluster—r730—k20—1--advertise=cluster-r730-k20-1:2375 consul://cluster—r730—1cluster-r730-1:8500 docker ps echo End of the script. EOF
docker pull swarm
docker pull progrium/consul
docker pull hello-world