19. April 2021

How to do an ICMP ping of a Service in Kubernetes

When moving software to the cloud you may encounter a component that relies on good old ICMP ping.

The problem is that Kubernetes does not support ICMP ping between services. Nigel Poulton described reasons in his post.

But what if the software depends on ICMP ping because it’s hardcoded since days of the pre-cloud era?

One way to solve the problem and make ICMP ping between Service working in Kubernetes is to use the following trick which has two steps:
– open TCP tunnel which forwards a port of service to localhost
– define host alias in /etc/hosts pointing to 127.0.0.1

The trick is based on the simple idea that you can ping localhost and talk to the port with local address which is then forwarded to the desired address.

Commands to add ICMP ping to service “myservice”:

socat tcp-listen:8000,reuseaddr,fork tcp:myservice:8000
echo "127.0.0.1 myservice" >>/etc/hosts

Test:

ping myservice
nc -z myservice 8000

The solution is definitely not 100% bullet-proof, but it can be a good workaround until the software is fixed.

8. June 2019

How to add custom mapping of a hostname to IP address in Android Emulator

There is a simple trick which allows your application to resolve a hostname to IP address defined by you even in cases when you do not have access to DNS server. This trick could be also used when you’re connected via VPN and the emulator is not able to resolve DNS record available only in private network.

Let’s add following hostname record which should be resolved by application on Android:

192.168.1.2 test.georgik.rocks

First of all, you need to start your AVD with parameter ‘-writable-system’, because emulator’s filesystem is by default read-only.

Let’s get names of available AVDs.

Example for macOS:

cd ~/Library/Android/sdk/tools
./emulator -avd -list

The output might look like:

Pixel_2_API_23
Pixel_2_API_24

Start the emulator:

./emulator -avd "Pixel_2_API_23" -writable-system

You should see the following warning:

emulator: WARNING: System image is writable

The emulator will start. Now you need to remount the filesystem so it will become writable. This could be done via adb tool which is in platform-tools directory.

Version for macOS:

cd ~/Library/Android/sdk/platform-tools
./adb remount

Now you can start the shell and append the line with configuration to /etc/hosts:

./adb shell 'echo "192.168.1.2 test.georgik.rocks" >> /etc/hosts'

Now you can test the configuration by ping:

root@generic_x86_64:/etc # ping test.georgik.rocks
PING test.georgik.rocks (192.168.1.2) 56(84) bytes of data.