Difference between revisions of "Kubernetes"

From 6bit.ch wiki
Jump to navigation Jump to search
Line 2: Line 2:


== kubectl ==
== kubectl ==
=== get ===
<code>kubectl get pods</code> Show all pods</br>
<code>kubectl get pods</code> Show all pods</br>
<code>kubectl get pods -o wide</code> Show all pods with more info</br>
<code>kubectl get pods -o wide</code> Show all pods with more info</br>
</br>
</br>
<code>kubectl get replicationcontroller</code> Show all replication controllers</br>
<code>kubectl get replicaset</code> Show all replica sets</br>
=== run/create ===
<code>kubectl run <pod-name> --image=nginx</code> Run new nginx pod</br>
<code>kubectl run <pod-name> --image=nginx</code> Run new nginx pod</br>
</br>
<code>kubectl create -f <defintion.yaml></code> Create new object from <definition.yaml> file</br>
=== describe/edit/delete ===
<code>kubectl describe pod <pod-name></code> Describe pod</br>
<code>kubectl describe pod <pod-name></code> Describe pod</br>
<code>kubectl edit pod <pod-name></code> Edit pod with editor</br>
<code>kubectl edit pod <pod-name></code> Edit pod with editor</br>
<code>kubectl delete pod <pod-name></code> Delete pod from default namespace</br>
<code>kubectl delete pod <pod-name></code> Delete pod from default namespace</br>
=== scale ===
<code>kubectl scale --replicas=5 replicaset <replicaset-name></code> Edit the current replicas without editing the file (fleeting?).
=== explain ===
<code>kubectl explain <something></code> 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.</br>
<nowiki>apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
    type: front-end
spec:
  containers:
  - name: nginx-container
    image: nginx</nowiki>
=== Example .yaml for Replication Controller ===
This configuration defines a replication controller for the example "myapp-pod" nginx pod.
<nowiki>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</nowiki>
=== Example .yaml for Replica Set ===
This configuration defines a replica set for the example "myapp-pod" nginx pod.
<nowiki>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</nowiki>

Revision as of 18:05, 22 January 2026

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