Skip to content

Instantly share code, notes, and snippets.

@diafour
Last active October 3, 2017 14:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diafour/11ce941356c847d24c86e6bda3f55e58 to your computer and use it in GitHub Desktop.
Save diafour/11ce941356c847d24c86e6bda3f55e58 to your computer and use it in GitHub Desktop.
Get rid of kubectl in redis sidecar
#!/usr/bin/env bash
# https://github.com/CommercialTribe/kube-redis/blob/develop/sidecar.sh
KUBE_TOKEN=$(</var/run/secrets/kubernetes.io/serviceaccount/token)
KUBE_CA=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
KUBE_NS=$(</var/run/secrets/kubernetes.io/serviceaccount/namespace)
KUBE_URL="https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT_HTTPS"
hosts () {
curl -sS --cacert $KUBE_CA -H "Authorization: Bearer $KUBE_TOKEN" \
https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT_HTTPS/api/v1/namespaces/$KUBE_NS/pods?labelSelector=$lables \
| jq -r '.["items"][] | .["status"]["podIP"]' \
| grep --invert-match $ip
}
set-role-label () {
curl -sS --cacert $KUBE_CA -H "Authorization: Bearer $KUBE_TOKEN" \
-H "Content-Type:application/json-patch+json" -X PATCH \
--data '[{"op":"replace","path":"/metadata/labels/role", "value": "$1" }]' \
https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT_HTTPS/api/v1/namespaces/$KUBE_NS/pods/`hostname`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment