notes blog about

Kubernetes is a distributed operating system. Applications running on it are called cloud native. See What is Kubernetes? for more.

Config and basic concepts

kubectl cluster configuration

kubectl config view

Context

# list contexts
kubectl config get-contexts

# switch context
kubectl config use-context <context-name>

Namespace

# all namespaces in a cluster, need admin rights
kubectl get namespaces

Basic objects

# view Kubernetes objects/resources
kubectl get all [-l app=nginx] # all objects [with a label app=nginx]
kubectl get <type>             # all objects of given type
kubectl get <type> <object>    # specific object

# details about an object
kubectl describe <type> <object>

# create, update objects
kubectl apply -f obj.yaml

# delete objects
kubectl delete -f obj.yaml  # no additional prompting!
kubectl delete <type> <object>

Pod

# Pod manifest - just a text-file representation of the Kubernetes API object
$ cat kuard-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: kuard
spec:
  containers:
    - image: gcr.io/kuar-demo/kuard-amd64:1
      name: kuard
      ports:
        - containerPort: 8080
          name: http
          protocol: TCP
# Creating a Pod
kubectl apply -f kuard-pod.yaml

What should I put into a single pod?

Deployment

One way to manage a deployment:

kubectl create deployment quotes-prod --image=reisinge/quotes
kubectl scale deployment quotes-prod --replicas=3
kubectl label deployment quotes-prod ver=1 env=prod

Service

One way to create a service:

kubectl expose deployment quotes-prod --port=80 --target-port=5000

Exposing services outside of the cluster

Service of type NodePort

Ingress

Service of type LoadBalancer

Resources