DNS round robin test (Load balancing):

DNS round robin test:

Ever since Docker engine 1.11, we can have multiple containers on a created network respond to the same DNS address (Load balancing).

Using image: elasticsearch:2
Option: --net-alias search
For example, start two elasticsearch containers with "–net-alias search" and from within the network, using the ‘search’ as the DNS name for connecting, you’d get 1 of the 2 servers at random.
Run alpine nslookup search with --net to see the two containers list for the same DNS name.
Run centos curl -s search:9200 with --net multiple times until you see both "name" fileds show

// Creating a network "mohi_nw":
PS C:\Users\MOHI> docker network create mohi_nw
bdc0a10f5d4acdc26b70953ab8233c5fe858b4cc265453f278bbc670f4f52b6d

// Creating two containers of "elasticsearch":
PS C:\Users\MOHI> docker container run -d --net mohi_nw --net-alias search elasticsearch:2
Unable to find image 'elasticsearch:2' locally
2: Pulling from library/elasticsearch
05d1a5232b46: Pull complete
5cee356eda6b: Pull complete
89d3385f0fd3: Pull complete
65dd87f6620b: Pull complete
78a183a01190: Pull complete
1a4499c85f97: Pull complete
2c9d39b4bfc1: Pull complete
1b1cec2222c9: Pull complete
59ff4ce9df68: Pull complete
1976bc3ee432: Pull complete
a27899b7a5b5: Pull complete
b0fc7d2c927a: Pull complete
6d94b96bbcd0: Pull complete
6f5bf40725fd: Pull complete
2bf2a528ae9a: Pull complete
Digest: sha256:41ed3a1a16b63de740767944d5405843db00e55058626c22838f23b413aa4a39
Status: Downloaded newer image for elasticsearch:2
4fd6c4c81d858e61414d7c66af81d9ba29443d41ed62ab18586ec9cf9ca8c093

PS C:\Users\MOHI> docker container run -d --net mohi_nw --net-alias search elasticsearch:2
9d19a976898957aa57d0abcdfcee982782bd762e4cc8c6ae4d0a31fea6f71dcc

PS C:\Users\MOHI> docker container ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
9d19a9768989        elasticsearch:2     "/docker-entrypoint.…"   3 minutes ago       Up 3 minutes        9200/tcp, 9300/tcp   nostalgic_visvesvaraya
4fd6c4c81d85        elasticsearch:2     "/docker-entrypoint.…"   6 minutes ago       Up 5 minutes        9200/tcp, 9300/tcp   fervent_antonelli

Now we need to run a test to make sure we can get to both of these with the same DNS names. so creating few dockers to test DNS (nslookup and curl)

PS C:\Users\MOHI> docker container run --rm --net mohi_nw alpine nslookup search
nslookup: can't resolve '(null)': Name does not resolve

Name:      search
Address 1: 172.19.0.2 search.mohi_nw
Address 2: 172.19.0.3 search.mohi_nw

// Checking the load balancing by using centos container with the curl:

PS C:\Users\MOHI> docker container run --rm --net mohi_nw centos curl -s search:9200
Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
729ec3a6ada3: Pull complete
Digest: sha256:f94c1d992c193b3dc09e297ffd54d8a4f1dc946c37cbeceb26d35ce1647f88d9
Status: Downloaded newer image for centos:latest
{
  "name" : "Arena",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "4SKj4oiTQhK4nJXPZWhPHg",
  "version" : {
    "number" : "2.4.6",
    "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
    "build_timestamp" : "2017-07-18T12:17:44Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.4"
  },
  "tagline" : "You Know, for Search"
}
PS C:\Users\MOHI> docker container run --rm --net mohi_nw centos curl -s search:9200
{
  "name" : "Polaris",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "iLhlDVkJQP6ZuhBjdVyHAg",
  "version" : {
    "number" : "2.4.6",
    "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
    "build_timestamp" : "2017-07-18T12:17:44Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.4"
  },
  "tagline" : "You Know, for Search"
}

PS C:\Users\MOHI> docker container run --rm --net mohi_nw centos curl -s search:9200
{
  "name" : "Polaris",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "iLhlDVkJQP6ZuhBjdVyHAg",
  "version" : {
    "number" : "2.4.6",
    "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
    "build_timestamp" : "2017-07-18T12:17:44Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.4"
  },
  "tagline" : "You Know, for Search"
}
PS C:\Users\MOHI> docker container run --rm --net mohi_nw centos curl -s search:9200
{
  "name" : "Arena",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "4SKj4oiTQhK4nJXPZWhPHg",
  "version" : {
    "number" : "2.4.6",
    "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
    "build_timestamp" : "2017-07-18T12:17:44Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.4"
  },
  "tagline" : "You Know, for Search"
}



///  Same DNS round robin testing with the different alias value as "test":

PS C:\Users\MOHI> docker container run -d --net mohi_nw --net-alias test elasticsearch:2
852b8032318f224f060a4faf3d8f3272040bc14a5582c3a0d7f0a0ad37347ec7
PS C:\Users\MOHI> docker container run -d --net mohi_nw --net-alias test elasticsearch:2
9417e1493b28999385a072db6f65e46e83fcf1253ed221ec5fb61eb0aa0438cb
PS C:\Users\MOHI> docker container run --rm --net mohi_nw alpine nslookup search
nslookup: can't resolve '(null)': Name does not resolve

Name:      search
Address 1: 172.19.0.2 search.mohi_nw
Address 2: 172.19.0.3 search.mohi_nw
PS C:\Users\MOHI> docker container run --rm --net mohi_nw alpine nslookup test
nslookup: can't resolve '(null)': Name does not resolve

Name:      test
Address 1: 172.19.0.5 test.mohi_nw
Address 2: 172.19.0.4 test.mohi_nw
PS C:\Users\MOHI> docker container run --rm --net mohi_nw centos curl -s test:9200
{
  "name" : "Nikki",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "tkoLDOgKQHO7qyCguKTA9g",
  "version" : {
    "number" : "2.4.6",
    "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
    "build_timestamp" : "2017-07-18T12:17:44Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.4"
  },
  "tagline" : "You Know, for Search"
}
PS C:\Users\MOHI> docker container run --rm --net mohi_nw centos curl -s test:9200
{
  "name" : "Brothers Grimm",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "qg_eVQhISLC7UxyKTicXIQ",
  "version" : {
    "number" : "2.4.6",
    "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
    "build_timestamp" : "2017-07-18T12:17:44Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.4"
  },
  "tagline" : "You Know, for Search"
}

No comments:

Post a Comment