Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am mvasilenko on github.
  • I am mvasilenko (https://keybase.io/mvasilenko) on keybase.
  • I have a public key ASASSXmI8z0EAqmbnrGYI04yWDdRLrffy8uXpNl6aXd55wo

To claim this, I am signing this object:

# for importing cloudflare hosted dns zones into terraform
# list zones
curl -s -X GET "https://api.cloudflare.com/client/v4/zones/?per_page=100" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json"| jq -r '.result[] | "\(.id) \(.name)"'
# list records at the zone 1234567890
curl -X GET "https://api.cloudflare.com/client/v4/zones/1234567890/dns_records?per_page=100" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json"| jq -r '.result[] | "\(.id) \(.name)
@mvasilenko
mvasilenko / terraform_cloudflare_import.sh
Created November 11, 2020 15:15
import Cloudflare DNS record into terraform state
# set your CloudFlare key & email
export auth_email=$CLOUDFLARE_EMAIL
export auth_key=$CLOUDFLARE_TOKEN
# list your DNS zones hosted at CloudFlare
curl -s -X GET "https://api.cloudflare.com/client/v4/zones/?per_page=100" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json"| jq -r '.result[] | "\(.id) \(.name)"'
# expected output:
# a3c9c7d3861e52cf23c835102c258d63 example1.com
# f47d1debb65621ca89039b9fbfeb726a example2.com
---
apiVersion: v1
kind: Namespace
metadata:
name: ns1
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: ns1-sa
get_network_mode() {
docker inspect --format='{{.HostConfig.NetworkMode}}' "$1"
}
created_by_kubelet() {
[[ $(docker inspect --format='{{.Name}}' "$1") =~ ^/k8s_ ]]
}
@mvasilenko
mvasilenko / mongodb_copy_all_indexes_for_collection.js
Created March 6, 2019 07:30
MongoDB copy all indexes for collection
db.getCollectionInfos().forEach(function(coll) {
if (coll.type === "collection" ) {
db[coll.name].getIndexes().forEach(function(index) {
if ("id" !== index.name) {
//print( JSON.stringify( index ))
var indexKey = index.key // save the key, and transform index into the "options"
delete index.v
delete index.key
index.background = true // optional: force background to be true
print("db." + coll.name + ".createIndex(" + JSON.stringify(indexKey) + ", " + JSON.stringify(index) + ")");
@mvasilenko
mvasilenko / mongodb_list_indexes_all_db.js
Last active March 6, 2019 07:27
mongodb list all indexes for all databases
// List all indexes in all databases
db.getMongo().getDBNames().forEach(function(dbName) {
if (dbName != "admin" && dbName != "local" && dbName != "config") {
db.getSiblingDB(dbName).getCollectionNames().forEach(function(coll) {
db.getSiblingDB(dbName)[coll].getIndexes().forEach(function(index) {
if ("id" !== index.name) {
print("db.getSiblingDB('" + dbName + "')." + coll + ".ensureIndex(" + tojson(index.key) + ")");
}
});
@mvasilenko
mvasilenko / AKS Setup Script
Created September 29, 2018 06:51 — forked from seanw122/AKS Setup Script
This script will setup a new Azure Resource Group and Azure Kubernetes Service cluster environment also with an Azure Container Registry resource.
## This creates a working single node Azure Kubernetes Cluster
## and with an Azure Container Registry. Note, the ACR is in
## the same resource group as the AKS for demo purposes. For
## dev you should have ACR in separate resource group.
echo "Beginning AKS Setup for Demo"
date
AKS_RESOURCE_GROUP=aks-rg1
AKS_CLUSTER_NAME=aks-c1
$ kubectl run nginx --image=nginx --dry-run -o yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
creationTimestamp: null
labels:
run: nginx
name: nginx
spec:
@mvasilenko
mvasilenko / gist:316ce0399ce8a95bc3e6ab0d1b71e882
Created May 17, 2018 09:48
delete k8s pods stuck in Terminating state
#!/bin/bash
# get namespaces list
NAMESPACES=$(kubectl get namespaces --output=jsonpath={.items..metadata.name})
# delete stuck pods in each namespace
for NS in $NAMESPACES;do
kubectl get pods -n $NS | awk "\$3==\"Terminating\" {print \"kubectl delete -n $NS pod \" \$1 \" --grace-period=0 --force\"}" | xargs -0 bash -c
done