Kubernetes and Helm (and other stuff)

Kubernetes Articles

Kubernetes Tools - Basic list

Kubectl and Kustomize

Microcks - testing with Kubernetes

Kubernetes Notes

Kubernetes Overview

Components

Kubernetes commands

# kubectl but my alias is "k"

# Listing stuff
kubectl get pods --all-namespaces            # list pods in all namespaces not just the current one
k get pods -n kubernetes-system              # List pods in a given namespace
kubectl get pods -o wide                     # Get a lot more details
kubectl get pods -w                          # Watch (useful waiting for stuff to get running)
kubectl get pods -l some-label                # List pods with a given label
kubectl get pods -l some-label --show-labels  # Show the labels

# Adding a label
kubectl label pod <somepodname> <somelabel>=true

# all running services - get the ports!
kubectl get service --all-namespaces

# all images inside the K3S cluster (but again Lens will probably be better for it)
docker exec k3d-k3s-default-server-0 sh -c "ctr image list"

Admin stuff

# Create a namespace
kubectl create namespace <namespace_name>

# Creating a rolebinding for a service account
kubectl create rolebinding -n "<somens>" edit --clusterrole=edit --serviceaccount="<somens>":<someaccount>

# Running a command as a service account or some other user to see if it is possible
kubectl --as=system:serviceaccount:"$NS":$SA auth can-i use

# kube-apiserver command
kubectl exec -it -n kube-system kube-apiserver-kind-control-plane -- kube-apiserver -h

Getting a shell to a running container


# Basic form
kubectl exec --stdin --tty shell-demo -- /bin/bash

Inter pod communication

K9s Useful Commands

K9s Commands cheatsheet

  • The ":" is used as a command prefix and then can be followed by a command
    • :pods - see pods
    • :svc - see services
    • :deploy - see deployments
    • :sts - see stateful sets
    • :rs - see replica sets
    • :ns - see namespaces
    • :no - see nodes
    • :sec - see secrets
    • :cm - config maps
  • :xray -> different views of the cluster with a tree layout

Simple yaml for a pod

apiVersion: v1
kind: Pod
metadata:
  name: ubuntu
  labels:
    app: ubuntu
spec:
  containers:
  - image: ubuntu
    command:
      - "sleep"
      - "604800"
    imagePullPolicy: IfNotPresent
    name: ubuntu
  restartPolicy: Always

Helm

Configmaps in helm

  • https://stackoverflow.com/questions/69837364/helm-configmap-in-values-yaml