Difference between revisions of "Kubernetes"

From 6bit.ch wiki
Jump to navigation Jump to search
Line 7: Line 7:
<code>kubectl explain <pods> --recursive</code> Explain something
<code>kubectl explain <pods> --recursive</code> Explain something
=== get ===
=== get ===
<code>kubectl get <all/pods/replicationcontroller/replicaset/deployment/ns/svc</code> Show all/replicationcontroller/replicaset/deployment/namespace/service objects</br>
<code>kubectl get <all/pods/replicationcontroller/replicaset/deployment/ns/svc/nodes</code> Show all/replicationcontroller/replicaset/deployment/namespace/service objects</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>
=== run/create ===
=== 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>

Revision as of 17:22, 26 January 2026

k8s

kubectl

api-resources

kubectl api-resources List available resources

explain

kubectl explain <pods> --recursive Explain something

get

kubectl get <all/pods/replicationcontroller/replicaset/deployment/ns/svc/nodes Show all/replicationcontroller/replicaset/deployment/namespace/service objects
kubectl get pods -o wide Show all pods with more info

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 Files

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

Example .yaml for Deployment

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

apiVersion: apps/v1
kind: Deployment
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

Example .yaml for Namespace

This configuration defines a new namespace dev.

apiVersion: v1
kind: Namespace
metadata:
  name: dev

Command: kubectl create namespace dev

Example .yaml for Resource Quota

This configuration defines a resource quota compute-quota for namespace dev.

apiVersion: v1
kind: ResourceQuota
metadata:
  name: compute-quota
  namespace: dev
spec:
  hard:
    pods: "10"
    requests.cpu: "4"
    requests.memory: 5Gi
    limit.cpu: "10"
    limit.memory: 10Gi

Imperative Commands

Can be tested with: --dry-run=client
kubectl run --image=nginx nginx
kubectl create deployment --image=nginx nginx
kubectl expose deployment nginx --port 80
kubectl edit deployment nginx
kubectl scale deployment nginx --replicas=5
kubectl set image deployment nginx nginx=nginx:1.18