Skip to content

Instantly share code, notes, and snippets.

View codesenju's full-sized avatar

Lehlogonolo N. Masubelele codesenju

View GitHub Profile
@codesenju
codesenju / .bash_profile
Created November 23, 2023 20:28
kubectl_shortcuts
alias k=kubectl
alias kgc='kubectl config get-contexts'
alias kuc='kubectl config use-context'
alias kn='kubectl config set-context --current --namespace'
@codesenju
codesenju / force-remove-namespace.sh
Last active July 29, 2023 20:57
Removes a namespace stuck in terminating status
#!/bin/bash
set -e
# Check if the NAMESPACE argument is provided
if [ -z "$1" ]; then
echo "Error: NAMESPACE argument not provided"
echo "Usage: $0 NAMESPACE"
exit 1
fi
@codesenju
codesenju / trust-template.json
Created July 5, 2023 16:36
trust-template.json for IRSA
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::${AWS_ACCOUNT_ID}:oidc-provider/oidc.eks.${AWS_REGION}.amazonaws.com/id/${OIDC_PROVIDER_ID}"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"oidc.eks.${AWS_REGION}.amazonaws.com/id/${OIDC_PROVIDER_ID}:sub": "system:serviceaccount: ${NS}:${SA}",
"oidc.eks.${AWS_REGION}.amazonaws.com/id/${OIDC_PROVIDER_ID}:aud": "sts.amazonaws.com"
@codesenju
codesenju / cluster-autoscaler-rbac.yaml
Created July 5, 2023 16:17
cluster-autoscaler-rbac.yaml
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: cluster-autoscaler
labels:
k8s-addon: cluster-autoscaler.addons.k8s.io
k8s-app: cluster-autoscaler
rules:
- apiGroups: [""]
@codesenju
codesenju / .vimrc
Created June 2, 2023 06:29
Vim for yaml editing
set number
autocmd FileType yaml,yml setlocal ts=2 sts=2 sw=2 et ai
set colorcolumn=80
set cursorcolumn
@codesenju
codesenju / ecs-exec.md
Created April 4, 2023 12:04
ECS EXEC A GUIDE

Ecs Exec A Guide

Prerequisite

[+] Install SessonManager on local machine, alternatively you can use AWS CloudShell. [+] IAM permissions required for ECS Exec, see[2].

export cluster_name=**
export private_subnet_one=**
export private_subnet_two=**
export container_security_group=**
@codesenju
codesenju / containerd.md
Last active March 21, 2023 21:13
containerd.md

Containerd

List containers with crt in k8s.io namespace

ctr -n k8s.io container ls

Display PID namespace processes that are running

ps -e -o pidns,pid,args
@codesenju
codesenju / nginx.conf
Created February 15, 2023 15:52
SSL NGINX | Replace /etc/nginx/conf.d/default.conf
server {
listen 80;
listen 443 ssl;
server_name nginx.example.com;
ssl_certificate /certs/nginx.example.com.pem;
ssl_certificate_key /certs/nginx.example.com.key;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
@codesenju
codesenju / EXPOSING_SERVICES_ON_EKS.MD
Created February 8, 2023 08:28
Exposing Services on EKS
@codesenju
codesenju / ecs_run_tasks.MD
Last active January 11, 2023 19:45
Run 6 ECS tasks with lambda triggered by Eventbridge scheduler

Here is the AWS CLI command to create an ECS task definition:

cat <<EOF> task-definition.json
{
  "family": "eb-start-ecs-stask",
    "taskRoleArn": "arn:aws:iam::${AWS_ACCOUNT_ID}:role/ecsTaskExecutionRole",
    "executionRoleArn": "arn:aws:iam::${AWS_ACCOUNT_ID}:role/ecsTaskExecutionRole",
    "networkMode": "bridge",
    "containerDefinitions": [
      {