Skip to content

Latest commit

 

History

History

Ch02

Chapter 2: Kubernetes Architecture

Check cluster info

kubectl cluster-info
kubectl get nodes -o wide
kubectl describe nodes
kubectl get all
kubectl get all --all-namespaces

List resources

kubectl api-resources

Create pod

Use run and --restart=Never:

kubectl run nginx --image=nginx --restart=Never

Create deployment

Do not use --restart=Never

kubectl run nginx --image=nginx

To have multiple replicas use --replicas=n, to export the service on a port use --port=PORT, to create the service use --expose

kubectl run nginx --image=nginx --replicas=6 --port=80 --expose

Check nginx

Get the service IP or, if there is no service (--expose wasn't used), get the pod IP:

kubectl get svc nginx     # Service IP
kubectl get pods -o wide  # Pod IP

Assuming --port=80 was used:

kubectl run busybox --image=busybox -it --rm --restart=Never -- wget -O- 10.107.69.177:80

Multiple containers

  1. Create pod manifest:

    kubectl run nginx --image=nginx --restart=Never --dry-run=true -o yaml > nginx.yaml
  2. Edit it to add a second container inside spec.containers[], for example:

  - name: fdlogger
    image: fluent/fluentd
  1. Create the pod:

    kubectl create -f nginx.yaml

Execute a command inside specific container

kubectl exec nginx -it -c fdlogger -- /bin/sh