Ben Chuanlong Du's Blog

It is never too late to learn.

Tips on Kubernetes

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Tutorials

https://www.youtube.com/watch?v=ZpbXSdzp_vo

Some Kubernetes Distributions

Microk8s seems like a good option.

  • k3s - a light-weight Kubernetes distribution ideal for edge and development - compatible with Raspberry Pi & ARM64 (Packet, AWS Graviton)

  • k3d - makes k3s available on any computer where Docker is also running

  • microk8s - a Kubernetes distribution, specifically for Ubuntu users.

  • minikube - a popular, but heavy-weight option that creates a Linux virtual machine your computer using VirtualBox or similar

  • Docker for Mac/Windows - Docker's Desktop edition has an option to run a local Kubernetes cluster

Authentication

Pull an Image from a Private Registry

Define a Command and Arguments for a Container

Define a Command and Arguments for a Container

Define command as ["/busybox/sh", "-c", "tail -f /dev/null"] instead of ["/busybox/sh", "-c", "tail", "-f", "/dev/null"] .

One-time Job

Running one-time jobs during Kubernetes deployments

Request Resource

https://cloud.google.com/blog/products/containers-kubernetes/kubernetes-best-practices-resource-requests-and-limits

https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/

https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/

Configure Quality of Service for Pods

Kubertenes Deployment

Kubertenes Deployment

Below is an example YAML configuration file.

---
apiVersion: v1
kind: Service
metadata:
  name: helloworldserivce
spec:
  selector:
    app: hello-world
  ports:
    - protocol: "TCP"
      port: 8080
      targetPort: 80
      nodePort: 30001
  type: LoadBalancer


---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  replicas: 5
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-world
        image: tutum/hello-world
        ports:
        - containerPort: 80

Another good example is to Deploy Apache Ray on Kubernetes .

in you namespace, you can run kubectl get resourcequota to check your quota

kubectl version list

kubectl get namespace

kubectl get namespace -l account.kubernetes.io/name=your_account

kubectl config get-contexts

kubectl get account chdu -o yaml

kubectl get application jupyterhub -o yaml

kubectl get namespace your_namespace -o yaml

kubectl get rc,pod,svc -n your_namespace

Run command in a pod.

kubectl exec -it pod_name -n your_namespace -- /bin/bash

Copy files to a pod.

kubectl -n your_namespace cp local_path_1 ... local_path_n pod_name:/destination/dir/

Copy files to a pod.

kubectl -n your_namespace cp pod_name:/some/path/1 pod_name:/some/path/2 /local/destination/dir

Delete a pod. Notice that a new pod will be created to replace the deleted pod if there's no enough replicas. If you want to delete a pod completely (without replacement), you have to delete the corresponding deployment instead.

kubectl -n your_namespace delete pods pod_name

List deployments in a namespace.

kubectl -n ms get deployments

Delete a deployment.

kubectl -n your_namespace delete deployment deployment_name

References

Comments