Visualizing K8s service interactions

An old peeve of mine was to be able to see the interactions among services in a kubernetes cluster nee namespace. I stumbled across Otterize and their wonderful network-mapper tool. It will give you a list of all the services and what they call. It will even create a PNG map for you. Alas a huge PNG file with itty-bitty letters in the legends. Whereas I am thankful for this tool, I wanted something sexier.

I remember some time ago I had used mermaid files to create SVG graphs. I took another look into otterize's output and it seems to me that it was screaming to become a mermaid. So I helped it out. This small script will take Otterize's output , convert it to mermaid format ( a clumsy one to be frank), and proceeds to create an SVG file. You can use a web browser to view your SVG file.

#!/bin/bash
#
# script to convert otterize output to mermaid and then svg
# Angelos Karageorgiou   - Jan 2 2024
#
TOSKIP="^skipme"
namespace=$(kubectl config view --minify -o jsonpath='{..namespace}')

(
echo "flowchart LR"
otterize -n $namespace network-mapper list | while read line
do
  # beginning of a section 
  found=$(echo "$line" | grep 'calls:$')
  if [[ $? -eq 0 ]]
  then
    source=$(echo $line | sed -e "s/ in namespace $namespace calls://g")
    continue
  fi
  # the service that is called
  dest=$(echo $line | sed -e 's/^-//g' -e "s/ in namespace $namespace//g")
  echo "$source --> $dest" | grep -v $TOSKIP
done
) > /tmp/$namespace.maid

# generate the svg now
mmdc -i /tmp/$namespace.maid -o /tmp/$namespace.svg
ls /tmp/$namespace*        

It has a couple of dependencies

  1. The mermaid JS app
  2. Chromium
  3. And on occasion the puppeteer framework

npm install @mermaid-js/mermaid-cli 
sudo apt install puppeteer chromium-browser        

Happy new year everybody!

要查看或添加评论,请登录

Angelo K.的更多文章

  • Old habits in modern DevOps

    Old habits in modern DevOps

    I am old , really, I remember writing TSRs in x86 Assembly for MS/DoS. I also remember the frantic digital dash of…

    1 条评论
  • Harq’ al’Ada (Break the habit)

    Harq’ al’Ada (Break the habit)

    I have been listening and reading all sorts of proposals on what Greece needs so that it can recover from its endemic…

    3 条评论
  • Why I hate the current trend of "education is not for everyone"

    Why I hate the current trend of "education is not for everyone"

    Without any respect whatsoever I consider articles and memes currently trending about how "education is superfluous"…

    3 条评论

社区洞察

其他会员也浏览了