Skip to content

Instantly share code, notes, and snippets.

View WalBeh's full-sized avatar

Walter Behmann WalBeh

  • 07:46 (UTC +02:00)
View GitHub Profile
package main
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
#!/usr/bin/env python3
"""
This script is used to update the JMX exporter version in the CrateDB StatefulSet.
JMX exporter is referenced in
- the initContainer,
- the CRATE_JAVA_OPTS environment variable, and
- the volumeMounts and
- sql_exporter image.
@WalBeh
WalBeh / py
Created May 22, 2024 09:26
k8s update deployment and cronjob
#!/usr/bin/env python3
""" Update the backup image in the cratedDB namespaces.
The script iterates over all cratedbs in a k8s context and updates tag on the deployment and cronjob
using the backup image.
The script can be run standlone/locally, or on-demand in the cluster via CI/CD. Runtime
behaviour and configuration is controlled via environment variables.
@WalBeh
WalBeh / gc_image_updater.py
Created December 6, 2023 14:46
Update cratedb over all namespace (label selector)
#!/usr/bin/env python3
# https://pip.wtf
def pip_wtf(command):
import os, os.path, sys
t = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".pip_wtf." + os.path.basename(__file__))
sys.path = [p for p in sys.path if "-packages" not in p] + [t]
os.environ["PATH"] += os.pathsep + t + os.path.sep + "bin"
os.environ["PYTHONPATH"] = os.pathsep.join(sys.path)
if os.path.exists(t): return
@WalBeh
WalBeh / image_updater.py
Last active December 6, 2023 10:30
k8s python client that updates an image tag
#!/usr/bin/env python3
# https://pip.wtf
def pip_wtf(command):
import os, os.path, sys
t = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".pip_wtf." + os.path.basename(__file__))
sys.path = [p for p in sys.path if "-packages" not in p] + [t]
os.environ["PATH"] += os.pathsep + t + os.path.sep + "bin"
os.environ["PYTHONPATH"] = os.pathsep.join(sys.path)
if os.path.exists(t): return
@WalBeh
WalBeh / trivy-helper.sh
Last active October 18, 2023 17:49
planned workaround
sanitize() {
local s="${1?need a string}" # receive input in first argument
s="${s//[^[:alnum:]]/-}" # replace all non-alnum characters to -
s="${s//+(-)/-}" # convert multiple - to single -
s="${s/#-}" # remove - from start
s="${s/%-}" # remove - from end
echo "${s,,}" # convert to lowercase
}
#
# ansible-playbook ./cordon-drain-check.yml --extra-vars "cx=aks2-westeurope np_to_drain=nodepool2"
#
- name: Debug Output
ansible.builtin.debug:
msg: Working on ------ {{ item }}
- name: 1 --- PRE-Flight check cratedbs status {{ item }}
shell: "{{ kubectl }} --context {{ cx }} get cratedbs -A | grep -v NAMESPACE | grep -v GREEN"
register: cratedbs
@WalBeh
WalBeh / 403.md
Created September 19, 2022 14:46
> cd /var/log/nginx
> ag " 403 "

24666:104.156.87.83 - - [18/Sep/2022:20:42:09 +0000] "GET /docs/sql-99/en/latest/c.html HTTP/1.1" 403 4537 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
25238:104.156.83.129 - - [18/Sep/2022:21:10:20 +0000] "GET /docs/crate/tutorials/en/latest/self-hosted/index.html HTTP/1.1" 403 4537 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
25431:167.82.236.22 - - [18/Sep/2022:21:19:31 +0000] "GET /docs/cloud/howtos/en/latest/ HTTP/1.1" 403 4537 "-" "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
25910:140.248.77.128 - - [18/Sep/2022:21:42:01 +0000] "GET /docs/crate/howtos/en/latest/ HTTP/1.1" 403 4531 "-" "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.5195.102 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
26120:23.235.43.63 - - [18/Sep/2022:21:52:55 +0000] "GET /docs/crate/tutorials/en/latest/_st
import yaml
import boto3
import re
import json
# kubectl get cratedbs -A -o yaml > cratedbs2.yaml  ✔  aks1-westeurope/aa6c3932-424e-4bdd-a4eb-b5d0dd2ae4fa ⎈
# kubectl get projects -o yaml -A > projects2.yaml  ✔  aks1-westeurope/aa6c3932-424e-4bdd-a4eb-b5d0dd2ae4fa ⎈
# croud clusters list -r aks1.westeurope.azure --sudo -o json > croud_cluster_list.json

Setup microk8s

Following the instructions from https://microk8s.io/docs

sudo snap install microk8s --classic --channel=1.21

sudo usermod -a -G microk8s $USER  
sudo chown -f -R $USER ~/.kube