This is an ansible playbook for creating a secured and dockerized private kafka and elasticsearch cluster with logstash as connectors. It uses kibana and elasticsearch-kopf as UI and oauth2_proxy as security frontend.
A few steps to take before running the playbook:
-
Make sure that
docker 1.10.3is installed locally. -
Install
docker-machine v0.6.0locally and usedocker-machineto create aswarmcluster with anoverlaynetwork{{ default_network }}("andofaelk_default") with at least two instances. One of them will act as thegatewayand the others asnodes. They are treated as the destination hosts.gatewayrequirements at least 1GB ram.nodesrequire a lot more becauseelasticsearchrequires a lot more RAM for good performance. Normally 16GB is the minimum. -
Create your own private/public key pair and add the public key to all destination hosts'
~/.ssh/authorized_keys. Use your private key for accessing the destination hosts. -
If you are testing the package locally, there is no need for installing
docker-machineand creating theoverlaynetwork. Create a docker group and add your user(sudo usermod -aG docker $(whoami)) so that you could rundockerwithoutsudo. Next, create a privatebridgenetwork withdocker network create {{ default_network }}. -
Make sure all distination hosts have
python2.7installed. -
If you would like to create a private docker registry and use it for all your images, you could do so with dockreg. In which case, make sure
pipand python packagepexpectare installed at registry host. -
Install
ansible 2.0.0.2and its dependencies locally. -
Open the inventory file staging and modify the destinations accordingly and update the variables stored in the files in the vars/ directory.
-
Choose a vault passphrase and use the same passphrase for the following two steps.
-
Run
ansible-vault create vars/common_vaultand add the following variables for passwords:vault_ca_passvault_registry_pass
-
Run
ansible-vault create vars/vaultand add your google app client info, for more information on google app client, please visit google developer console:vault_google_app_client_idvault_google_app_client_secret
-
Add a valid redirect uri for
elasticsearchto your google app client via google developer console. This should be the same ashttps://{{ elasticsearch_domain }}/oauth2/callbackfrom yourgatewayhost variables. Or if it does not have a public domain, it should behttps://{{ expose_elasticsearch_as }}:{{ expose_elasticsearch }}/oauth2/callback. Note that google app redirect uri is required to be either a public top-level domain or localhost, meaning{{expose_elasticsearch_as}}is required to be127.0.0.1unless google changes its policies in the future. You could use the-Loption ofsshto create a ssh tunnel for accessing remote host's port locally, orautosshif you want persistant connection. For example, suppose you have set-up the cluster already, useautossh -f -L {{ expose_elasticsearch }}:127.0.0.1:{{ expose_elasticsearch }} -i {{ hostvars['gateway']['ansible_ssh_private_key_file'] }} {{ hostvars['gateway']['ansible_user'] }}@{{ hostvars['gateway']['ansible_default_ipv4']['address']}} -N
to create the tunnel and point your browser at
https://127.0.0.1:{{ expose_elasticsearch }}/_plugin/kopfto interact with your elasticsearch cluster. -
Add a valid redirect uri for
kibanato your google app client via google developer console. This should be the same ashttps://{{ kibana_domain }}/oauth2/callbackfrom yourgatewayhost variables. Or if it does not have a public domain, it should behttps://{{ expose_kibana_as }}:{{ expose_kibana }}/oauth2/callback. Refer to previous step. -
Please make sure that
docker 1.10.0and its dependencies are installed and running as a service on all destination hosts and that{{ ansible_user }}has access to it withoutsudo. -
Create all images. Run the following command at project folder:
ansible-playbook -i staging --ask-vault-pass images.yaml
To start all containers:
ansible-playbook -i staging --ask-vault-pass -K run.yaml
Andokaelk_Container_Structure_Diagram.pdf illustrates the complete container structure when you have one gateway and three nodes. Gateway also hosts a private docker registry in this case. The registry does not reside in the overlay network but has port 5000 open.
To stop and remove all containers:
ansible-playbook -i staging --ask-vault-pass stop.yaml
To clean up all generated contents:
ansible-playbook -i staging --ask-vault-pass -K clean.yaml
The -K option is only necessary if you are not operating as the root user and there is a root password.