Compare commits
7
Commits
4bc1af17cc
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8aabe2532 | ||
|
|
86f971fb35 | ||
|
|
fd14473b99 | ||
|
|
e8fe8c449c | ||
|
|
3433a2f7f2 | ||
|
|
88c70a96ab | ||
|
|
abf2e93f3f |
@@ -12,11 +12,13 @@ Kubernetes is an open‑source platform that automates the deployment, scaling,
|
||||
- [OOMKilled](#oomkilled)
|
||||
- [Attach to an pod](#attach-to-an-pod)
|
||||
- [Run command on pod](#run-command-on-pod)
|
||||
- [Container TTY](#container-tty)
|
||||
- [Persistent volumes](#persistent-volumes)
|
||||
- [create PersistentVolumes - host path](#create-persistentvolumes---host-path)
|
||||
- [find persistent volume used pvc](#find-persistent-volume-used-pvc)
|
||||
- [Patch pv - change to retain policy](#patch-pv---change-to-retain-policy)
|
||||
- [Patch pv - remove finalizers](#patch-pv---remove-finalizers)
|
||||
- [check orphans](#check-orphans)
|
||||
- [persistent volume claims](#persistent-volume-claims)
|
||||
- [Create an pod with PVC](#create-an-pod-with-pvc)
|
||||
- [kubectl](#kubectl)
|
||||
@@ -29,6 +31,7 @@ Kubernetes is an open‑source platform that automates the deployment, scaling,
|
||||
- [Manifest - StringData](#manifest---stringdata)
|
||||
- [Inline with heredoc and environment variables](#inline-with-heredoc-and-environment-variables)
|
||||
- [substr](#substr)
|
||||
- [annotations](#annotations)
|
||||
- [nodes](#nodes)
|
||||
- [taints](#taints)
|
||||
- [add taint](#add-taint)
|
||||
@@ -43,6 +46,7 @@ Kubernetes is an open‑source platform that automates the deployment, scaling,
|
||||
- [Deployment - rollout restart](#deployment---rollout-restart)
|
||||
- [Daemonset](#daemonset)
|
||||
- [Daemonset - rollout restart](#daemonset---rollout-restart)
|
||||
- [services](#services)
|
||||
- [certs](#certs)
|
||||
- [list all certs](#list-all-certs)
|
||||
- [get cert end date](#get-cert-end-date)
|
||||
@@ -55,6 +59,7 @@ Kubernetes is an open‑source platform that automates the deployment, scaling,
|
||||
- [k3s](#k3s)
|
||||
- [Install / Setup](#install--setup)
|
||||
- [prune old images](#prune-old-images)
|
||||
- [kill all](#kill-all)
|
||||
- [Prune ephemeral containerd data](#prune-ephemeral-containerd-data)
|
||||
- [check system logs](#check-system-logs)
|
||||
- [Workarounds \& Fixes](#workarounds--fixes)
|
||||
@@ -221,7 +226,7 @@ kubectl delete pod -n appNamespace -l app=myAppName
|
||||
|
||||
### OOMKilled
|
||||
|
||||
**list all OOMKilled pods:**
|
||||
**list all OOMKilled:**
|
||||
|
||||
``` bash
|
||||
kubectl get events --all-namespaces | grep -i "OOMKilled"
|
||||
@@ -233,6 +238,16 @@ kubectl get pods --all-namespaces \
|
||||
| grep OOMKilled
|
||||
```
|
||||
|
||||
On cluster node
|
||||
|
||||
```bash
|
||||
sudo dmesg -T | grep -i kill
|
||||
sudo dmesg -T | grep -Ei "oom|kill"
|
||||
sudo journalctl -k | grep -Ei "oom|kill"
|
||||
sudo journalctl -k --since "1 hour ago" | grep -Ei "oom|kill"
|
||||
sudo journalctl -k -o short-iso | grep -Ei "oom|kill"
|
||||
```
|
||||
|
||||
### Attach to an pod
|
||||
|
||||
Attach connects your terminal to the main process of the container (PID 1), or another running process if specified.
|
||||
@@ -261,6 +276,20 @@ POD_NAME=$(kubectl get pod -l app=$MY_APP_NAME -n $NAMESPACE -o jsonpath='{.item
|
||||
kubectl exec -n $NAMESPACE -it ${POD_NAME} -- sh
|
||||
```
|
||||
|
||||
### Container TTY
|
||||
|
||||
```yaml
|
||||
...
|
||||
command: ["bash", "-c"]
|
||||
tty: true
|
||||
args:
|
||||
- |
|
||||
while true; do
|
||||
sleep 100
|
||||
done
|
||||
...
|
||||
```
|
||||
|
||||
``` bash
|
||||
# bash
|
||||
POD_NAME=$(kubectl get pod -l app=myAppName -n appNamespace -o jsonpath='{.items[0].metadata.name}')
|
||||
@@ -318,6 +347,39 @@ kubectl patch pv $PV_NAME \
|
||||
-p '{"metadata":{"finalizers": null}}'
|
||||
```
|
||||
|
||||
### check orphans
|
||||
|
||||
**Execute on host:**
|
||||
|
||||
``` bash
|
||||
#/bin/bash
|
||||
STORAGE_DIR="/var/lib/rancher/k3s/storage"
|
||||
# clean if already been used
|
||||
unset PV_PATHS
|
||||
declare -A PV_PATHS
|
||||
ORPHANS=()
|
||||
|
||||
for name in $(kubectl get pv -o jsonpath='{.items[*].metadata.name}'); do
|
||||
path=$(kubectl get pv ${name} -o jsonpath='{.spec.local.path}' 2>/dev/null)
|
||||
# check if path is no empty
|
||||
[[ -n "${path}" ]] && PV_PATHS["${path}"]="1"
|
||||
done
|
||||
|
||||
for dir in "$STORAGE_DIR"/*; do
|
||||
[ -d "$dir" ] || continue
|
||||
if [[ -z "${PV_PATHS[$dir]}" ]]; then
|
||||
ORPHANS+=("$dir")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${#ORPHANS[@]} -eq 0 ]]; then
|
||||
echo "No orphans found."
|
||||
else
|
||||
echo "orphans:"
|
||||
printf "%s\n" "${ORPHANS[@]}"
|
||||
fi
|
||||
```
|
||||
|
||||
### persistent volume claims
|
||||
|
||||
``` yaml
|
||||
@@ -537,6 +599,14 @@ envsubst < ./secret.yaml | kubectl apply -f -
|
||||
|
||||
```
|
||||
|
||||
## annotations
|
||||
|
||||
``` bash
|
||||
kubectl annotate secret test-your-domain-tls \
|
||||
-n test-namespace \
|
||||
replicator.v1.mittwald.de/replicate-to="namespace-1,namespace-2" --overwrite
|
||||
```
|
||||
|
||||
## nodes
|
||||
|
||||
**Get nodes info:**
|
||||
@@ -677,6 +747,19 @@ NAMESPACE="???"
|
||||
kubectl rollout restart daemonset $NAME -n $NAMESPACE
|
||||
```
|
||||
|
||||
## services
|
||||
|
||||
**nuke finalizers:**
|
||||
|
||||
``` bash
|
||||
SERVICE="traefik"
|
||||
NAMESPACE="traefik-public"
|
||||
kubectl patch service ${SERVICE} \
|
||||
-n ${NAMESPACE} \
|
||||
--type=merge \
|
||||
-p '{"metadata":{"finalizers":[]}}'
|
||||
```
|
||||
|
||||
## certs
|
||||
|
||||
### list all certs
|
||||
@@ -809,6 +892,17 @@ crictl rmi --prune
|
||||
sudo ctr --address /run/k3s/containerd/containerd.sock images prune --all
|
||||
```
|
||||
|
||||
### kill all
|
||||
|
||||
``` bash
|
||||
k3s-killall.sh
|
||||
```
|
||||
|
||||
If k3s using mount. Force kill by mount
|
||||
|
||||
```bash
|
||||
kill -9 $(lsof +f -- /mount | awk 'NR>1 {print $2}')
|
||||
```
|
||||
|
||||
### Prune ephemeral containerd data
|
||||
|
||||
|
||||
+100
-13
@@ -9,26 +9,95 @@ AGE_FILE=age.agekey
|
||||
age-keygen -o ${AGE_FILE}
|
||||
```
|
||||
|
||||
**Create key and Import to kubernetes:**
|
||||
**Example using sops decryption:**
|
||||
|
||||
``` bash
|
||||
NAMESPACE=ns-name
|
||||
AGE_FILE=deploy/flux/.env.d/age.agekey
|
||||
SECRET_NAME=flux-sops-age
|
||||
|
||||
# creates age key
|
||||
age-keygen -o ${AGE_FILE}
|
||||
# imports to an namespace
|
||||
cat ${AGE_FILE} |
|
||||
kubectl create secret generic ${SECRET_NAME} \
|
||||
--namespace=${NAMESPACE} \
|
||||
--from-file=age.agekey=/dev/stdin
|
||||
```yaml
|
||||
apiVersion: kustomize.toolkit.fluxcd.io/v1
|
||||
kind: Kustomization
|
||||
metadata:
|
||||
name: sample-sync
|
||||
spec:
|
||||
interval: 1m
|
||||
sourceRef:
|
||||
kind: GitRepository
|
||||
name: git-repo-name
|
||||
path: deploy/sample-app
|
||||
prune: true
|
||||
decryption:
|
||||
provider: sops
|
||||
secretRef:
|
||||
name: flux-sops-age
|
||||
```
|
||||
|
||||
**Importing sops private key:**
|
||||
|
||||
Using kustomization used by operator to deploy base fluxcd manifests for deployments and reconciliation.
|
||||
|
||||
``` bash
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
namespace: your-namespace
|
||||
resources:
|
||||
- sample-app.yaml
|
||||
secretGenerator:
|
||||
- name: flux-sops-age
|
||||
files:
|
||||
- "age.agekey=./.env.d/age.agekey" #change to private key file path
|
||||
generatorOptions:
|
||||
disableNameSuffixHash: true
|
||||
```
|
||||
|
||||
**Import using kubectl:**
|
||||
|
||||
```bash
|
||||
SECRET_NAME="flux-sops-age"
|
||||
NAMESPACE="your-namespace"
|
||||
kubectl create secret generic ${SECRET_NAME} \
|
||||
--namespace=${NAMESPACE} \
|
||||
--from-file=age.agekey=/dev/stdin #change to private key file path
|
||||
```
|
||||
|
||||
```yaml
|
||||
apiVersion: kustomize.toolkit.fluxcd.io/v1
|
||||
kind: Kustomization
|
||||
metadata:
|
||||
name: sample-sync
|
||||
spec:
|
||||
interval: 1m
|
||||
sourceRef:
|
||||
kind: GitRepository
|
||||
name: git-repo-name
|
||||
path: deploy/sample-app
|
||||
prune: true
|
||||
decryption:
|
||||
provider: sops
|
||||
secretRef:
|
||||
name: flux-sops-age
|
||||
```
|
||||
|
||||
|
||||
## kustomization prune
|
||||
|
||||
**Disable:**
|
||||
|
||||
``` bash
|
||||
FLUX_RESOURCE_NAME="???"
|
||||
FLUX_RESOURCE_NS="???"
|
||||
kubectl patch kustomization ${FLUX_RESOURCE_NAME} -n ${FLUX_RESOURCE_NS} --type merge -p '{"spec":{"prune":false}}'
|
||||
```
|
||||
|
||||
**Enable:**
|
||||
|
||||
``` bash
|
||||
FLUX_RESOURCE_NAME="???"
|
||||
FLUX_RESOURCE_NS="???"
|
||||
kubectl patch kustomization ${FLUX_RESOURCE_NAME} -n ${FLUX_RESOURCE_NS} --type merge -p '{"spec":{"prune":true}}'
|
||||
```
|
||||
|
||||
## kustomization helm release
|
||||
|
||||
**Disable:**
|
||||
|
||||
``` bash
|
||||
FLUX_RESOURCE_NAME="???"
|
||||
FLUX_RESOURCE_NS="???"
|
||||
@@ -42,3 +111,21 @@ FLUX_RESOURCE_NAME="???"
|
||||
FLUX_RESOURCE_NS="???"
|
||||
kubectl patch helmrelease ${FLUX_RESOURCE_NAME} -n ${FLUX_RESOURCE_NS} --type merge -p '{"spec":{"prune":true}}'
|
||||
```
|
||||
|
||||
## Reconcile
|
||||
|
||||
**Source git:**
|
||||
|
||||
``` bash
|
||||
FLUX_RESOURCE_NAME="???"
|
||||
FLUX_RESOURCE_NS="???"
|
||||
flux reconcile source git ${FLUX_RESOURCE_NAME} -n ${FLUX_RESOURCE_NS}
|
||||
```
|
||||
|
||||
**Kustomization:**
|
||||
|
||||
``` bash
|
||||
FLUX_RESOURCE_NAME="???"
|
||||
FLUX_RESOURCE_NS="???"
|
||||
flux reconcile kustomization ${FLUX_RESOURCE_NAME} -n ${FLUX_RESOURCE_NS}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user