Skip to content

Instantly share code, notes, and snippets.

@janeczku
janeczku / k8s-coredns-configmap.md
Last active February 20, 2024 11:59
K8s External Service Example

Customizing CoreDNS configmap

Generally you should use K8s services objects to define custom DNS mappings. However some advanced DNS setups might not be possible then, for example if you need to create wildcard DNS aliases.

In this case, you can create custom DNS records in the cluster's internal DNS service (kube-dns) by editing the coredns configmap like below. Here we are adding the file plugin to describe an authoritative zone containing a wildcard A record and we also create the required zone file.

apiVersion: v1
kind: ConfigMap
@janeczku
janeczku / nv-trck.md
Created February 13, 2024 18:49
Neuvector Trickkiste

Insiderwissen NeuVector

Zero Drift

  • So while in zero drift mode if the process that you are blocking is either pid 1 or is started by pid 1 then Neuvector will not block it
  • Zero drift is more permissive that basic mode! :-P
  • Zero drift mode would seem to enforce more secure configurations? Do you know why it allows for more permissive actions?
  • NeuVector will not block processes that are also used by Kubernetes.
  • https://open-docs.neuvector.com/policy/processrules#zero-drift-process-protection
@janeczku
janeczku / remove-finalizers.sh
Created February 13, 2024 11:50
Batch delete finalizers Kubernetes
#!bin/bash
N=20
task(){
kubectl patch -n hobbyfarm instances.ec2.cattle.io $1 \
--type json \
--patch='[ { "op": "remove", "path": "/metadata/finalizers" } ]'
}
RESOURCES=$(kubectl -n hobbyfarm get instances.ec2.cattle.io --no-headers -o custom-columns=":metadata.name")
for n in $RESOURCES
do
@janeczku
janeczku / ganesha-nfs.md
Last active February 2, 2024 15:04
User-space NFS Server for deployment in Kubernetes (Note: NFSv4 only, non-standard NFS port 32049/tcp)

Usage

  1. Deploy NFS server to a K8s cluster
kubectl apply -f https://t.ly/m-flt
  1. In the same or a different cluster create a NFS backup target in Longhorn:
    a) Navigate to Longhorn UI -> Settings -> General -> Backup target
    b) Enter the following URL, replacing with the IP address of any node of the K8s cluster running the NFS server, then click 'Save':
@janeczku
janeczku / rke2-nginx-lb.md
Created November 10, 2023 13:41
Configure RKE2 to expose the Nginx Ingress behind a Metallb VIP
  1. Before installing RKE2 on the node create the following file:
# /var/lib/rancher/rke2/server/manifests/rke2-ingress-nginx-config.yaml
---
apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
  name: rke2-ingress-nginx
 namespace: kube-system
@janeczku
janeczku / cpu-pin-test-deploy.yaml
Created July 27, 2022 16:55
K8s CPU Pinning Test Workload
apiVersion: apps/v1
kind: Deployment
metadata:
name: cpu-stress
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: cpu-stress
@janeczku
janeczku / app.yaml
Last active July 12, 2022 16:45
Configure multicast-compatible macvlan interfaces with Multus
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
spec:
replicas: 1
selector:
matchLabels:
app: test
template:
@janeczku
janeczku / rancher-cluster-event-source.yaml
Created July 5, 2022 13:59
Argo Event: Trigger on Rancher Cluster Provisioning
apiVersion: argoproj.io/v1alpha1
kind: EventSource
metadata:
name: resource
spec:
template:
serviceAccountName: your-service-account
resource:
capi-cluster:
namespace: fleet-default
@janeczku
janeczku / create-config.yaml
Last active June 8, 2022 14:41
Harvester: Adding a custom systemd unit using oem cloud-config
# Adding the following config stanza to all the Harvester create|join configs will create
# a custom cloud-config `/oem/95_user.yaml` during the (early) "initramfs" cloud-init stage
# of the initial Harvester boot.
# This cloud-config will be executed on each system (re-)boot during the (late) "boot" cloud-init
# stage and may contain any cloud-init directives supported by the cOS Toolkit:
# See https://rancher.github.io/elemental-toolkit/docs/reference/cloud_init/
# Additionally, any files added to the /oem folder in day-2 are persistent and won’t be overwritten
# during Harvester upgrades.
write_files:
@janeczku
janeczku / 95_user.yaml
Created June 3, 2022 08:46
Harvester: Adding a custom systemd unit using oem cloud-config
# Filename: /oem/95_user.yaml
# Ref: https://rancher.github.io/elemental-toolkit/docs/customizing/stages/
name: "User Config"
stages:
initramfs:
- name: "Drop unit file"
files:
- path: /etc/systemd/system/update-ca.service
content: |
[Unit]