Skip to content

Instantly share code, notes, and snippets.

View sumanthkumarc's full-sized avatar

Sumanth Reddy sumanthkumarc

View GitHub Profile
@sumanthkumarc
sumanthkumarc / ns-delete.sh
Created February 3, 2022 09:13
namespace deletion
(
NAMESPACE=<your-rogue-namespace>
kubectl proxy &
kubectl get namespace $NAMESPACE -o json |jq '.spec = {"finalizers":[]}' > temp.json
curl -k -H "Content-Type: application/json" -X PUT --data-binary @temp.json 127.0.0.1:8001/api/v1/namespaces/$NAMESPACE/finalize
pkill -9 -f "kubectl proxy"
)
@sumanthkumarc
sumanthkumarc / foo-bar.yaml
Created February 3, 2022 08:46
namespace manifest
~ k get ns foo-bar -o yaml
apiVersion: v1
kind: Namespace
metadata:
name: foo-bar
selfLink: /api/v1/namespaces/foo-bar
spec:
finalizers:
- kubernetes
~ kubectl get clusterrole view -o yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
labels:
kubernetes.io/bootstrapping: rbac-defaults
rbac.authorization.k8s.io/aggregate-to-edit: "true"
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
rbac.authorization.k8s.io/aggregate-to-view: "true"
name: view-role-extras
rules:
- apiGroups:
- autoscaling
resources:
import CustomArgumentParser
from io import StringIO
import sys
parser = CustomArgumentParser(description='Process my command')
parser.add_argument('foo', type=str, help='Magic of foo')
parser.add_argument(
'--bar',
action='store',
required=False,
type=str,
@sumanthkumarc
sumanthkumarc / ArgumentParser.py
Created May 3, 2021 03:29
Custom Argument Parser class to use argparse in REST api app
from argparse import ArgumentParser
import sys as _sys
# Tested on Python 3.8. For version >=3.9, There is new exit_on_error flag in init function.
# Although it doesn't entirely help our use case, we should be passing our flag `exit_on_error`
# to the parent class init function.
class CustomArgumentParser(ArgumentParser):
def __init__(self, prog=None, exit_on_error=False):
from locust import User, task, constant, tag
from pymongo import MongoClient
from time import perf_counter
class Mongo:
conn = ""
def __init__(self):
cs = 'mongodb://mongodb-0:27017,mongodb-1:27011,mongodb-2:27012,mongodb-3:27013,mongodb-arbiter-0:27014'
# Make target
port-forward:
while true; do \
kubectl port-forward -n my-ns service/mongodb-0 27017:27017 & \
kubectl port-forward -n my-ns service/mongodb-1 27011:27017 & \
kubectl port-forward -n my-ns service/mongodb-2 27012:27017 & \
kubectl port-forward -n my-ns service/mongodb-3 27013:27017 & \
kubectl port-forward -n my-ns service/mongodb-arbiter-0 27014:27017 \
done;
@sumanthkumarc
sumanthkumarc / service_single_pod.yaml
Created October 17, 2020 06:27
service to select single pod in statefulset
apiVersion: v1
kind: Service
metadata:
name: mongodb-0
labels:
app.kubernetes.io/name: mongodb
app.kubernetes.io/component: mongodb
spec:
type: ClusterIP
clusterIP: None
@sumanthkumarc
sumanthkumarc / cluster.yml
Created April 19, 2019 06:20
sample cluster file
nodes:
- address: master.my-domain.com
user: my-user
role:
- controlplane
- etcd
- address: worker1.my-domain.com
user: my-user
role:
- worker