Skip to content

Instantly share code, notes, and snippets.

@alexec
Created June 29, 2021 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexec/8a9fa2dcddfb05831c3f39950bfa2024 to your computer and use it in GitHub Desktop.
Save alexec/8a9fa2dcddfb05831c3f39950bfa2024 to your computer and use it in GitHub Desktop.
How to use tcpkill with Docker

How to use tcpkill to simulate network failure (e.g. for FMEA testing) by breaking network connections between your pod and a remote service.

I'm assuming your pod runs as non-root.

You'll need to add your user to the sudoers file, so in your Dockerfile:

FROM ubuntu
# ...
RUN adduser --disabled-password --uid 9653 runner
RUN adduser runner sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER 9653

When you start you pod, add the NET_ADMIN capability, otherwise you'll get permission denied errors.

Start your pod as normal, then start TCP kill:

kubectl exec -ti ${podName} -c ${containerName} -- sudo tcpkill port ${portNumber}

Network connections are not severed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment