Yet another coding blog?

May 4, 2019 19:21 · 285 words · 2 minute read general kubernetes

So, yet another coding blog? Yeah, a couple of things coming together: in March 2019 I joined AWS as a developer advocate for containers with a special focus on security. I have been and continue to develop tooling, mainly using Go and shell scripts. In addition, I finally wanted to start sharing stuff I’ve been collecting over the past 10+ years in various (private) repos and gists, mainly code snippets or commands that make my life easier—since they helped me, why would they not be useful for others? :)

Here’s an example, if you’re dealing with a Kubernetes cluster and unsure about the API server URL:

$ kubectl get --raw=/api | \
          jq .serverAddressByClientCIDRs[0].serverAddress -r
ip-10-0-185-58.us-east-2.compute.internal:443

OK, wait. What happened here? Let’s break it apart.

First, we use the get verb of the kubectl command in raw mode (hence: --raw). This means we directly specify the path to hit, in our case /api. From this endpoint, we get something like:

{
  "kind": "APIVersions",
  "versions": [
    "v1"
  ],
  "serverAddressByClientCIDRs": [
    {
      "clientCIDR": "0.0.0.0/0",
      "serverAddress": "ip-10-0-121-66.us-east-2.compute.internal:443"
    }
  ]
}

In the next step we pipe this to jq to pull out the respective serverAddress field’s value. The popular and very useful JSON query tool called jq should be part of your toolbox anyways. Also, for further processing and to get a clean value (without the quotes) we use the -r option on jq, meaning “output raw strings, not JSON texts”.

And this is how you determine the API server’s URL. Got a better way? Let us know!

FWIW, I’m also open to concrete suggestions on topics in the cloud native space or if you have questions, I might as well write a post aiming to answer them.