Skip to content

Instantly share code, notes, and snippets.

View tanelmae's full-sized avatar
🏠
Working from home

Tanel Mae tanelmae

🏠
Working from home
  • Tallinn
  • 22:08 (UTC +03:00)
View GitHub Profile
@tanelmae
tanelmae / dm-gke.sh
Created October 29, 2018 13:58
Deployment Manager GKE permissions
#!/usr/bin/env bash
CURRENT_PROJECT=$(gcloud config get-value project)
PROJECT_NUMBER=$(gcloud projects describe ${CURRENT_PROJECT} --format='value(projectNumber)')
SERVICE_ACCOUNT="${PROJECT_NUMBER}@cloudservices.gserviceaccount.com"
kubectl create clusterrolebinding dm-admin-binding --clusterrole=cluster-admin --user=${SERVICE_ACCOUNT}
@tanelmae
tanelmae / gist:b638ba113bd394702038954dd2010da6
Created October 29, 2018 14:03
Get GKE context by name
# Assumes unique cluster names
function get-context() {
local CLUSTER_NAME=${1}
[ -z ${CLUSTER_NAME} ] && echo "Give cluster name" && return 1
local CURRENT_PROJECT=$(gcloud config get-value project)
local CLUSTER_ZONE=$(gcloud container clusters list --filter=name:${CLUSTER_NAME} --format='value(zone)')
[ -z ${CLUSTER_ZONE} ] && return 1
gcloud container clusters get-credentials ${CLUSTER_NAME} --zone=${CLUSTER_ZONE}
@tanelmae
tanelmae / gist:2f0655e0f445dabf4d9f6b02055ce8e9
Created October 29, 2018 15:08
Give cluster-admin role to current local user to the current kubectl context
function admin-me() {
kubectl create clusterrolebinding $(whoami)-admin-binding \
--clusterrole=cluster-admin \
--user=$(gcloud config get-value core/account)
}
@tanelmae
tanelmae / deploy-local.sh
Created November 1, 2018 14:41
Quick deployment to Docker Hub
#!/usr/bin/env bash
set -e
GIT_TAG=$(git rev-parse --short HEAD)
USERNAME=$(docker info | sed '/Username:/!d;s/.* //')
TOOL_NAME=$(basename $(pwd))
IMAGE_NAME="${USERNAME}/${TOOL_NAME}:${GIT_TAG}"
docker build -t ${IMAGE_NAME} .
@tanelmae
tanelmae / kubemciw.sh
Created March 15, 2019 07:20
kubemci wrapper
#!/usr/bin/env bash
if [[ $OSTYPE == "darwin"* ]]; then
KMCI_LINK="https://storage.googleapis.com/kubemci-release/release/latest/bin/darwin/amd64/kubemci"
else
KMCI_LINK="https://storage.googleapis.com/kubemci-release/release/latest/bin/linux/amd64/kubemci"
fi
LOCAL_BIN=$(pwd)/bin
# Use gcloud access token to fetch Stackdriver custom metrics descriptions
curl --silent --header "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
https://monitoring.googleapis.com/v3/projects/$(gcloud config get-value core/project)/metricDescriptors?filter=metric.type%3Dstarts_with%28%22custom.googleapis.com%2F%22%29
# Get all the custom metrics names with jq
curl --silent --header "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
https://monitoring.googleapis.com/v3/projects/$(gcloud config get-value core/project)/metricDescriptors?filter=metric.type%3Dstarts_with%28%22custom.googleapis.com%2F%22%29 | jq '.metricDescriptors[] | .name'
alias googleapis-curl='curl --silent --header "Authorization: Bearer $(gcloud auth application-default print-access-token)"'
cd /usr/local/etc/bash_completion.d
ln -s /Applications/Docker.app/Contents/Resources/etc/docker.bash-completion
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.bash-completion
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion
#!/bin/bash
# Based on:
# https://withblue.ink/2019/07/13/yes-you-can-run-docker-on-raspbian.html
set -e
sudo su
# Install some required packages first
apt-get update
apt-get install -y \
@tanelmae
tanelmae / coredns.service
Last active August 3, 2019 19:27
Running CoreDNS docker image with systemd
[Unit]
Description=CoreDNS
Requires=docker.service
After=docker.service
ConditionPathExists=/etc/coredns/Corefile
[Service]
ExecStartPre=/bin/bash -c "/usr/bin/docker container inspect coredns 2> /dev/null || /usr/bin/docker run -d --name coredns -p 53:53/udp --restart unless-stopped -v /etc/coredns:/conf coredns/coredns:1.6.0 -conf /conf/Corefile"
ExecStart=/usr/bin/docker start -a coredns
ExecStop=/usr/bin/docker stop coredns