Skip to content

Instantly share code, notes, and snippets.

View Becram's full-sized avatar

Bee Becram

View GitHub Profile
@Becram
Becram / webhook-mutate.go
Last active May 7, 2022 16:20
webhook-medium-2
// Mutate returns a new mutated pod according to lifespan tolerations rules
func (mpl containerResources) Mutate(pod *corev1.Pod) (*corev1.Pod, error) {
mpl.Logger = mpl.Logger.WithField("mutation", mpl.Name())
mpod := pod.DeepCopy()
resources, err := parseResources()
if err != nil {
return &corev1.Pod{}, err
}
@Becram
Becram / mutating-webhook.yaml
Last active May 7, 2022 16:10
k8s-blog-medium-1
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: "kubernetes-webhook.acme.com"
webhooks:
- name: "kubernetes-webhook.acme.com"
objectSelector:
matchLabels:
mutation-check: enabled
rules:
@Becram
Becram / podspec.go
Created May 2, 2022 12:33
podspec struct definition
// PodSpec is a description of a pod.
type PodSpec struct {
Volumes []Volume `json:"volumes,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name" protobuf:"bytes,1,rep,name=volumes"`
InitContainers []Container `json:"initContainers,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,20,rep,name=initContainers"`
Containers []Container `json:"containers" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,2,rep,name=containers"`
EphemeralContainers []EphemeralContainer `json:"ephemeralContainers,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,34,rep,name=ephemeralContainers"`
@Becram
Becram / go-module.go
Created May 2, 2022 12:03
sample deployment
package main
import (
"fmt"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
)
func main() {
@Becram
Becram / PrepareAWSClientVPN.md
Created November 28, 2021 13:07 — forked from monkut/PrepareAWSClientVPN.md
Prepare AWS Client VPN for connecting to a VPC without NAT/IGW

Prepare AWS Client VPN README

Prerequisites

  • AWS Account
  • Linux(like) System
  • awscli
@Becram
Becram / validate.sh
Last active May 27, 2021 07:02
Validate kustomization
set -o errexit
echo "INFO - Downloading Flux OpenAPI schemas"
mkdir -p /tmp/flux-crd-schemas/master-standalone-strict
curl -sL https://github.com/fluxcd/flux2/releases/latest/download/crd-schemas.tar.gz | tar zxf - -C /tmp/flux-crd-schemas/master-standalone-strict
# mirror kustomize-controller build options
kustomize_flags="--load-restrictor=LoadRestrictionsNone"
kustomize_config="kustomization.yaml"
@Becram
Becram / kubeseal-generator.sh
Created May 20, 2021 11:23
generate kubeseal secrets
#!/bin/bash
SECRET_NAME="apm-creds"
NAMESPACE="rasa"
ARRAY=("apm_server_url:t1"
"apm_secret_token:t2")
for secret in "${ARRAY[@]}" ; do
KEY="$(echo $secret | cut -d':' -f1 )"
VALUE="$(echo $secret | cut -d':' -f2-)"
# echo $KEY $VALUE
@Becram
Becram / sock-status.sh
Last active April 16, 2021 10:01
script to find the tcp connection status
#!/bin/bash
pods=$(kubectl get po -nlinkerd -ojsonpath="{range .items[*]}{.metadata.name} {.metadata.namespace}{'\n'}{end}")
IFS=" "
while read name namespace; do
tcp=$(kubectl exec -n $namespace $name linkerd-proxy -- cat /proc/net/tcp)
close_wait=$(echo $tcp | awk 'BEGIN {cnt=0} $4==08 {cnt++} END {print cnt}')
fin_wait_2=$(echo $tcp | awk 'BEGIN {cnt=0} $4==05 {cnt++} END {print cnt}')
#!/bin/bash
#set -x
AWS_DEFAULT_REGION=us-east-2
NR_MASTER=1
NR_NODES=2
SERVER_TYPE=t2.small
K8S_VERSION=v1.8.15
KOPS_VERSION=1.12.2
key=devops23
@Becram
Becram / get_nodes.py
Last active July 3, 2019 03:17
get_runing_nodes
#!/usr/bin/python
###################################################################
# Author Bikram Dhoju bikramdhoju.com.np
# Directions:
# Populate target_mac list with your list nodes
# change target_subnet to your subnet
# result is stored in output.json
####################################################################