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.3
is installed locally. -
Install
docker-machine v0.6.0
locally and usedocker-machine
to create aswarm
cluster with anoverlay
network{{ default_network }}
("andofaelk_default") with at least two instances. One of them will act as thegateway
and the others asnodes
. They are treated as the destination hosts.gateway
requirements at least 1GB ram.nodes
require a lot more becauseelasticsearch
requires 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-machine
and creating theoverlay
network. Create a docker group and add your user(sudo usermod -aG docker $(whoami)
) so that you could rundocker
withoutsudo
. Next, create a privatebridge
network withdocker network create {{ default_network }}
. -
Make sure all distination hosts have
python2.7
installed. -
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
pip
and python packagepexpect
are installed at registry host. -
Install
ansible 2.0.0.2
and 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_vault
and add the following variables for passwords:vault_ca_pass
vault_registry_pass
-
Run
ansible-vault create vars/vault
and add your google app client info, for more information on google app client, please visit google developer console:vault_google_app_client_id
vault_google_app_client_secret
-
Add a valid redirect uri for
elasticsearch
to your google app client via google developer console. This should be the same ashttps://{{ elasticsearch_domain }}/oauth2/callback
from yourgateway
host 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.1
unless google changes its policies in the future. You could use the-L
option ofssh
to create a ssh tunnel for accessing remote host's port locally, orautossh
if 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/kopf
to interact with your elasticsearch cluster. -
Add a valid redirect uri for
kibana
to your google app client via google developer console. This should be the same ashttps://{{ kibana_domain }}/oauth2/callback
from yourgateway
host 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.0
and 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.