Kubernetes

From 6bit.ch wiki
Revision as of 18:05, 22 January 2026 by Xbl (talk | contribs)
Jump to navigation Jump to search

k8s

kubectl

get

kubectl get pods Show all pods
kubectl get pods -o wide Show all pods with more info

kubectl get replicationcontroller Show all replication controllers
kubectl get replicaset Show all replica sets

run/create

kubectl run <pod-name> --image=nginx Run new nginx pod
kubectl create -f <defintion.yaml> Create new object from <definition.yaml> file

describe/edit/delete

kubectl describe pod <pod-name> Describe pod
kubectl edit pod <pod-name> Edit pod with editor
kubectl delete pod <pod-name> Delete pod from default namespace

scale

kubectl scale --replicas=5 replicaset <replicaset-name> Edit the current replicas without editing the file (fleeting?).

explain

kubectl explain <something> Explain <something>

Kubernetes Definition File

Example .yaml for Pod

This configuration defines a pod named "myapp-pod" that runs a single container using the nginx image.

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
    type: front-end
spec:
  containers:
  - name: nginx-container
    image: nginx

Example .yaml for Replication Controller

This configuration defines a replication controller for the example "myapp-pod" nginx pod.

apiVersion: v1
kind: ReplicationController
metadata:
  name: myapp-rc
  labels:
      app: myapp
      type: front-end
spec:
  template:
    metadata:
      name: myapp-pod
      labels:
        app: myapp
        type: front-end
    spec:
      containers:
      - name: nginx-container
        image: nginx
  replicas: 3

Example .yaml for Replica Set

This configuration defines a replica set for the example "myapp-pod" nginx pod.

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: myapp-replicaset
  labels:
      app: myapp
      type: front-end
spec:
  template:
    metadata:
      name: myapp-pod
      labels:
        app: myapp
        type: front-end
    spec:
      containers:
      - name: nginx-container
        image: nginx
  replicas: 3
  selector:
    matchLabels:
      type: front-end