Skip to content

Instantly share code, notes, and snippets.

View dejanu's full-sized avatar
🐵
all things are subject to interpretation...even API keys

dejanualex dejanu

🐵
all things are subject to interpretation...even API keys
View GitHub Profile
@dejanu
dejanu / k8s_upgrade.md
Last active October 1, 2024 20:48
Upgrading Kubernetes

The upgrade process (docs) follows the general procedure of:

- Upgrading the Kubernetes control plane with kubeadm (Kubernetes components and add-ons excluding the CNI)
- If applicable upgrading the CNI network plugin
- Upgrading the Kubernetes packages (kubelet, kubeadm, kubectl) on the control plane and worker nodes
- Upgrading the kubelet config on worker nodes with kubeadm
# check cluster nodes and version
kubectl  get no  -owide
@dejanu
dejanu / docker_flags.md
Last active October 2, 2024 17:48
Docker support Go templates to manipulate the output format
  • Output image name and tag: docker images --format '{{.Repository}} and {{.Tag}}'
  • Output image name, tag and elapsed time + timestamp since the image has been created: docker images --format "{{.Repository}}:{{.Tag}} {{.CreatedSince}} --> {{.CreatedAt}}"
  • Inspect Cmd for desired : docker inspect -f '{{.Config.Cmd}}' <IMAGE>
  • Inspect Entrypoint for desired : docker inspect -f '{{.Config.Entrypoint}} <IMAGE>'
  • Search if there are official images for desired : docker search --format "table {{.Name}}\t{{.StarCount}}\t{{.IsOfficial}}" <IMAGE>
  • Inspect attached containers to bridge network: docker inspect network bridge --format "{{json .Containers }}"
  • Inspect storage: docker info -f 'Storage drive: {{.Driver}} and storage path {{.DockerRootDir}}'
  • Inspect container runtimes: docker system info --format "{{.Runtimes}} {{.DefaultRuntime}}"
#!/usr/bin/env bash
###########################################
# ##
# @dejanualex: Trivy based image scanner ##
# ##
###########################################
version: '3.1'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
@dejanu
dejanu / pssh.sh
Created June 7, 2023 09:32
Simple shell script that achieves concurrent SSH connections using background processes
#!/bin/bash
## #####################################################################
## run concurrently command passed as argv on multiple remote servers ##
## UPDATE: servers array and user variable ##
########################################################################
# define an array of remote servers
servers=("server1.fqdn" "server2.fqdn" "server3.fqdn")
# Function to execute command on a remote server
execute_command() {
server=$1
@dejanu
dejanu / docker_engine.md
Last active September 7, 2024 20:48
Manage Docker and Display system-wide information
  • containers resource usage
# docker stats [OPTIONS] [CONTAINER...]
docker stats --no-stream
  • check the container runtimes
docker system info
docker system info --format "Runtimes: {{.Runtimes}} with default {{ .DefaultRuntime }}"
@dejanu
dejanu / capacity_mgmt.sh
Created December 8, 2022 16:02
wrapper for inspecting Requests/Limits for Pods
#!/usr/bin/env bash
#############################################################
# Purpose: wrapper for inspecting Requests/Limits for Pods ##
# @dejanualex ##
#############################################################
# read namespace and po
echo -e "Available namespaces are:\n $(kubectl get ns -o=custom-columns=NAMESPACES:.metadata.name) \n"
echo -e "\n Please write the name of the namespace for which you want to know the resource status:\n"
@dejanu
dejanu / k8s_metrics.md
Last active November 14, 2024 10:18
Kubernetes metrics to watch for capacity management

Nice and eazy Metrics

  • Information about Node:
# Gauge type metric

# CPU capacity <cores>
kube_node_status_capacity{resource="cpu"}

# Memory capacity <bytes>
@dejanu
dejanu / cluster_state_report.sh
Created August 10, 2022 20:55
wrapper for k8s cluster state report
#!/usr/bin/env bash
################################################################################################
# kubectl wrapper that generates a report concerning cluster state, ##
# which creates a dir with compiled information regarding: ##
# - control plane components status, cluster events, nodes description, and namespace events ##
################################################################################################
# Get nodes, componentsstatuses, and pods for control-plane
echo -e "\e[0;32m Cluster Nodes: \e[0m \n $(kubectl get nodes -owide)"
@dejanu
dejanu / aks_upgrade.sh
Last active May 5, 2022 16:01
Upgrade an Azure Kubernetes Service (AKS) cluster
# get available k8s versions for AKS, e.g. for location westeurope
az aks get-versions --location westeurope | jq ".orchestrators[] | .orchestratorVersion"
# get available versions for your AKS
az aks get-upgrades --resource-group <resourcegroup_name> --name <aks_name> --output table
# check your k8s version for control plane and woker node pool
az aks show -g <resourcegroup_name> -n <resourcegroup_name>| grep -E "orchestratorVersion|kubernetesVersion"
# update max-surge to 3 nodes, you can use percentage also e.g.50% (for a node surges half of the no of nodes from the node pool)