Zusammenfassung der Ressource
kubectl
Anmerkungen:
- https://kubernetes.io/docs/reference/kubectl/cheatsheet/https://kubernetes.io/docs/reference/kubectl/
https://kubernetes.io/docs/reference/kubectl/
- Useful
- kubectl create
Anmerkungen:
- Run kubectl create to see a list of objects that can be created with imperative commands.
- kubectl create deployment my-deployment --image=nginx
Anmerkungen:
- Create a deployment imperatively.
- kubectl create deployment my-deployment --image=nginx --dry-run -o yaml
Anmerkungen:
- Do a dry run to get some sample yaml without creating the object.
- kubectl create deployment my-deployment --image=nginx --dry-run -o yaml > deployment.yml
Anmerkungen:
- kubectl create -f deployment.yml
Anmerkungen:
- Create the object using the file.
- kubectl scale deployment my-deployment replicas=5 --record
Anmerkungen:
- Scale a deployment and record the command.
- kubectl describe deployment my-deployment
- kubectl apply -f FILENAME [flags]
- kubectl drain NODE [options]
- kubectl delete (-f FILENAME | TYPE [NAME | /NAME | -l label | --all]) [flags]
- kubectl describe (-f FILENAME | TYPE [NAME_PREFIX | /NAME | -l label]) [flags]
- kubectl exec POD [-c CONTAINER] [-i] [-t] [flags] [-- COMMAND [args...]]
- kubectl expose
- kubectl label
- kubectl logs POD [-c CONTAINER] [--follow] [flags]
- kubectl port-forward POD [LOCAL_PORT:]REMOTE_PORT [...[LOCAL_PORT_N:]REMOTE_PORT_N] [flags]
- kubectl uncordon NODE [options]
- kubectl version [--client] [flags]
- kubectl api-resources
- kubectl get pods <pod-name> --server-print=false
- kubecyl apply
- kubectl apply -f example-service.yaml
Anmerkungen:
- # Create a service using the definition in example-service.yaml.
- kubectl apply -f example-controller.yaml
Anmerkungen:
- # Create a replication controller using the definition in example-controller.yaml.
- kubectl apply -f <directory>
Anmerkungen:
- # Create the objects that are defined in any .yaml, .yml, or .json file within the <directory> directory.
- kubectl get
- kubectl get pods -o wide
- kubectl get replicationcontroller <rc-name>
Anmerkungen:
- # List the replication controller with the specified name in plain-text output format. Tip: You can shorten and replace the 'replicationcontroller' resource type with the alias 'rc'.
- kubectl get rc,services
Anmerkungen:
- # List all replication controllers and services together in plain-text output format.
- kubectl get ds
Anmerkungen:
- # List all daemon sets in plain-text output format.
- kubectl get pods --field-selector=spec.nodeName=server01
Anmerkungen:
- # List all pods running on node server01
- kubectl get pods -n kube-system
- kubectl get pods -n kube-system --selector k8s-app=calico-node
- kubectl get
pv
Anmerkungen:
- kubectl get pv -o yaml
_____to get the values and sort them
--sort-by=.spec....
- kubectl get pv --sort-by=.spec.capacity.storage
- kubectl config get-contexts
- kubectl config current-context
- kubectl config use-context my-cluster-name
- kubectl config set-context --current --namespace=ggckad-s2
- kubectl config set-context gce --user=cluster-admin --namespace=foo \ && kubectl config use-context
gce
- kubectl get pods -n beebox-mobile --kubeconfig /home/cloud_user/dev-k8s-config
- kubectl top po -n beebox-mobile --sort-by=cpu --selector=app=auth >
/home/cloud_user/cpu-pod-name.txt
- output systax
- kubectl [command] [TYPE] [NAME] -o <output_format>
Anmerkungen:
- The default output format for all kubectl commands is the human readable plain-text format. To output details to your terminal window in a specific format, you can add either the -o or --output flags to a supported kubectl command.
- Output format
- -o custom-columns=<spec>
Anmerkungen:
- Print a table using a comma separated list of custom columns.
- kubectl get pods <pod-name> -o
custom-columns=NAME:.metadata.name,RSRC:.metadata.resourceVersion
- -o custom-columns-file=<filename>
Anmerkungen:
- Print a table using the custom columns template in the <filename> file.
- kubectl get pods <pod-name> -o custom-columns-file=template.txt
Anmerkungen:
- where the template.txt file contains:
NAME RSRC
metadata.name metadata.resourceVersion
- -o json
Anmerkungen:
- Output a JSON formatted API object.
- -o jsonpath=<template>
Anmerkungen:
- Print the fields defined in a jsonpath expression.
- -o jsonpath-file=<filename>
- -o name
- -o wide
- -o yaml
- kubectl get pod web-pod-13je7 -o yaml
- kubectl get clusterrolebindings