Home

kubectl

:ID: ee377537-0c8d-48c9-a181-19a2cff8c4a7

Commands

  • View cluster information
kubectl cluster-info

Apply & Create

  • Just creates a resource
kubectl create ...
  • Create or modify a resource
kubectl apply -f pod.yml

Delete

Deleting a pod won't prevent it from being recreated.

kubectl delete pod [pod-name]

you need to delete it's deployment.

kubectl delete deployment [deployment-name]

Describe

kubectl describe pods <...>

Get

  • View all the resources
kubectl get all
  • Get information about the pods
kubectl get pods --watch
kubectl get pods -o wide
  • Get information about deployments
# Lists deployments and their labels
kubectl get deployment --show-labels
# Get deployments with a specific label
kubectl get deployment -l app=nginx

Port-forward

  • Forward port to enables external calls
kubectl port-forward [pod-name] [external-port]:[internal-port]
# For instance...
kubectl port-forward [pod-name] 8080:80

YAML

Pod

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
    ref: stable
spec:
  containers:
  - name: nginx
    image: nginx:alpine
    ports:
    - containerPort: 80

Pod Healthchecks

  • Probe Types
    • Readiness Probe: Defines when should a container start receiving traffic
    • Liveness Probe: Defines when a container is considered unhealthy and should, therefore, be restarted.
  • Action Types
    • ExecAction
    • TCPSocketAction
    • HTTPGetAction
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
    ref: stable
spec:
  containers:
  - name: nginx
    image: nginx:alpine
    ports:
    - containerPort: 80
    livenessProbe:
      httpGet:
	path: /index.html
	port: 80
      initialDelaySeconds: 15
      timeoutSeconds: 2
      periodSeconds: 5
      failureThreshold: 1
    readinessProbe:
      httpGet:
	path: /index.html
	port: 80
      initialDelaySeconds: 5
      periodSeconds: 10
      failureThreshold: 1
    resources:
      limits:
	memory: "128Mi" # 128 Mb
	cpu: "200m"     # 200 milicpu, i.e, 0.2 cpu or 20% cpu