Skip to content

Instantly share code, notes, and snippets.

@so0k
Last active August 7, 2023 06:16
Show Gist options
  • Save so0k/860b570276a86adc38b75cb859bf4c16 to your computer and use it in GitHub Desktop.
Save so0k/860b570276a86adc38b75cb859bf4c16 to your computer and use it in GitHub Desktop.
Alpine-shell

Getting an Alpine shell

Often usefull for in-cluster debugging.

$ kubectl run --generator=run-pod/v1 --image=alpine:3.5 -it alpine-shell -- /bin/sh

detach (without killing the container):

CTRL+P,CTRL+Q

re-attach with:

$ kubectl attach -it alpine-shell

Testing Services

Postgres

$ apk add --update postgresql-client
$ psql -h $PG_HOST -U $PG_USER -p 5432 -d $PG_DB

Redis

$ apk add --update redis
$ redis-cli -h $HOST PING
PONG

or just with telnet:

$ telnet $HOST 6379
> PING
+PONG
> QUIT

Memcached

# telnet is part of busy box
$ telnet $HOST 11211
> stats
> e

DNS Resolution

$ apk add --update bind-tools

# test for srv records for the port named "client" of etcd cluster
$ dig +nostats +nocmd +nocomments SRV _client._tcp.example-etcd-cluster.default.svc.cluster.local
_client._tcp.exam...local. 30 IN SRV 10 100 2379 example-etcd-cluster.default.svc.cluster.local.
example-etcd-cluster.default.svc.cluster.local. 30 IN A 10.3.0.196

# this returned port 2379 and IP 10.3.0.196 (VIP for the service)

Etcd

$ echo "@testing http://nl.alpinelinux.org/alpine/edge/testing" | tee -a /etc/apk/repositories
$ apk add --update etcd@testing
$ export ETCDCTL_API=3
$ export ETCDCTL_ENDPOINTS=example-etcd-cluster:2379

$ etcdctl endpoint health
$ etcdctl member list

notice:

$ kubectl get endpoints example-etcd-cluster -o json | jq -r ".subsets[].addresses[].ip"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment