k8s - Kubernetes

  • Cut-n-Paste
    # see krew above
    k top no
    k top po
    
    # troubleshooting
    kubectl get nodes -v=10
    kubectl events -n flux-system --for OCIRepository/podinfo --watch
    kubectl config set-context --current --namespace=<namespace-name>
    journalctl -u kubelet
    kubectl config get-contexts
    
    # new env
    asdf plugin list all
    asdf plugin add kubectl
    asdf plugin add flux2
    ...
    asdf list all <util> # get a list of available versions
    asdf install <util> <version>
    asdf set <util> <version> # set the version for this directory and below
    asdf current # list of active plugins
    
    kubectl version
    flux version
    
    k3s kubectl get nodes -o wide

  • Backup procedure
    # stop services for db backup
    kubectl scale deployment <deployment-name> --replicas=0 -n <namespace>
    kubectl patch cronjob <cronjob-name> -n <namespace> -p '{"spec": {"suspend": true}}'
    kubectl get pods -n <namespace>
    # backup
    kubectl scale deployment <deployment-name> --replicas=<original-replicas> -n <namespace>
    kubectl patch cronjob <cronjob-name> -n <namespace> -p '{"spec": {"suspend": false}}'
    # check
    kubectl get pods -n <namespace>
    kubectl get deployments -n <namespace>

  • Clients
    • kubectl
      export KUBECONFIG=$PWD/.kube/cp-kdev-k3s.yaml
      
      kubectl ctx
      kubectl ns
      kubectl auth can-i get pods
      kubectl describe pod -n x-production > mro/describe-pods-prod.yml
      kubectl logs podname -c containername --previous
      kubectl config view --minify
      kubectl exec -it x-production-api-xxx -- /bin/bash
  • Kubernetes As Service
  • Cost Cutting
    • Perfectscale for cost optimization
  • Karpenter
    10.4.18.35:8443->10.4.16.236:40672