Difference between revisions of "Kubectl"
Jump to navigation
Jump to search
(37 intermediate revisions by 4 users not shown) | |||
Line 3: | Line 3: | ||
== Installation == | == Installation == | ||
− | * To install in | + | * To install in [[macOS]] execute: <code>[[brew install kubernetes-cli]]</code> |
− | * | + | * [[Kubectl in Amazon Linux]] |
+ | * [[Ubuntu kubectl installation]] | ||
* <code>[[~/.kube/config]]</code> | * <code>[[~/.kube/config]]</code> | ||
+ | * [[scoop install kubectl]] | ||
== Commands == | == Commands == | ||
* <code>[[kubectl --help]]</code> | * <code>[[kubectl --help]]</code> | ||
+ | * <code>[[kubectl api-versions]]</code> | ||
* <code>[[kubectl apply]]</code> | * <code>[[kubectl apply]]</code> | ||
* <code>[[kubectl auth]]</code> | * <code>[[kubectl auth]]</code> | ||
* <code>[[kubectl create]]</code> | * <code>[[kubectl create]]</code> | ||
* <code>[[kubectl completion]]</code> | * <code>[[kubectl completion]]</code> | ||
− | * <code>[[kubectl config]]</code> | + | * <code>[[kubectl config]]</code>: <code>[[kubectl config use-context|config-use-context]]</code> |
+ | * <code>[[kubectl cp]]</code> | ||
* <code>[[kubectl debug]]</code> (since [[v1.18]], March 2020) | * <code>[[kubectl debug]]</code> (since [[v1.18]], March 2020) | ||
* <code>[[kubectl delete]]</code> | * <code>[[kubectl delete]]</code> | ||
Line 19: | Line 23: | ||
* <code>[[kubectl diff]]</code> (since [[v1.18]], March 2020) | * <code>[[kubectl diff]]</code> (since [[v1.18]], March 2020) | ||
* <code>[[kubectl edit]]</code> | * <code>[[kubectl edit]]</code> | ||
+ | * <code>[[kubectl explain]]</code> | ||
* <code>[[kubectl expose]]</code> | * <code>[[kubectl expose]]</code> | ||
* <code>[[kubectl exec]]</code> | * <code>[[kubectl exec]]</code> | ||
Line 24: | Line 29: | ||
* <code>[[kubectl label]]</code> | * <code>[[kubectl label]]</code> | ||
* <code>[[kubectl logs]]</code> | * <code>[[kubectl logs]]</code> | ||
+ | * <code>[[kubectl patch]]</code> | ||
* <code>[[kubectl port-forward]]</code> | * <code>[[kubectl port-forward]]</code> | ||
+ | * <code>[[kubectl proxy]]</code> | ||
* <code>[[kubectl plugin]]</code> | * <code>[[kubectl plugin]]</code> | ||
* <code>[[kubectl replace]]</code> | * <code>[[kubectl replace]]</code> | ||
Line 97: | Line 104: | ||
* [[Create and configure a basic Pod]] (<code>[[kubectl apply]]</code>) | * [[Create and configure a basic Pod]] (<code>[[kubectl apply]]</code>) | ||
* Read official <code>kubectl</code> cheat sheet: https://kubernetes.io/docs/reference/kubectl/cheatsheet/ | * Read official <code>kubectl</code> cheat sheet: https://kubernetes.io/docs/reference/kubectl/cheatsheet/ | ||
+ | * Check examples: https://www.codegrepper.com/code-examples/shell/kubectl+describe+ingress+output+yaml | ||
+ | * https://stackoverflow.com/questions/tagged/kubectl?tab=Votes | ||
+ | * [[Kubernetes quiz]] | ||
+ | * [[Merge multiple kubeconfigs]]: <code>[[~/.kube/config]]s</code> into one using <code>[[kubectl konfig merge]]</code> | ||
== Related == | == Related == | ||
* [[Krew]] | * [[Krew]] | ||
− | * [[kops]] | + | * <code>[[kops]]</code> |
− | * <code>[[aws eks]] --region $(terraform output -raw region) update-kubeconfig --name $(terraform output -raw cluster_name)</code> | + | * [[Kots]] kubectl plugin |
+ | * [[K9s]] | ||
+ | * <code>[[aws eks]] --region $([[terraform output -raw]] region) [[update-kubeconfig]] --name $([[terraform output -raw]] cluster_name)</code> | ||
+ | * <code>[[kubectl-convert]]</code> | ||
+ | * <code>[[kubeadm]]</code> | ||
+ | * <code>[[Error: flags cannot be place before plugin name]]</code> | ||
+ | * <code>[[kubectl.kubernetes.io]]</code> | ||
+ | * [[kubectl (alias)]] | ||
+ | * [[Terraform: kubectl provider]] | ||
+ | * <code>[[kubectl --request-timeout]]</code> | ||
== See also == | == See also == | ||
* {{Kubernetes components}} | * {{Kubernetes components}} | ||
* {{kubectl}} | * {{kubectl}} | ||
− | |||
[[Category: Kubernetes]] | [[Category: Kubernetes]] |
Latest revision as of 16:02, 10 July 2024
wikipedia:kubectl
is a command line interface for running commands against Kubernetes clusters.[1]
Contents
Installation[edit]
- To install in macOS execute:
brew install kubernetes-cli
- Kubectl in Amazon Linux
- Ubuntu kubectl installation
~/.kube/config
- scoop install kubectl
Commands[edit]
kubectl --help
kubectl api-versions
kubectl apply
kubectl auth
kubectl create
kubectl completion
kubectl config
:config-use-context
kubectl cp
kubectl debug
(since v1.18, March 2020)kubectl delete
kubectl describe
kubectl diff
(since v1.18, March 2020)kubectl edit
kubectl explain
kubectl expose
kubectl exec
kubectl get all | nodes | pvc | pods | replicaset .../...
kubectl label
kubectl logs
kubectl patch
kubectl port-forward
kubectl proxy
kubectl plugin
kubectl replace
kubectl rolling-update
kubectl rollout
kubectl set
kubectl top
kubectl virt
Kubectl information commands[edit]
kubectl cluster-info
:dump
kubectl config view
kubectl get pods
:kubectl get pods -n kube-system
kubectl top pod PODNAME
kubectl describe
kubectl get namespaces
kubectl get nodes
kubectl get services
kubectl get configmaps
kubectl logs
kubectl version
kubectl operation commands[edit]
kubectl create
kubectl delete pod
kubectl delete namespace MY_NAMESPACE
- Connect to a Pod:
kubectl exec -it YOUR_POD_NANE -- /bin/bash
kubectl command reference[edit]
The following table includes short descriptions and the general syntax for all of the kubectl
operations:[2]
- Apply
kubectl apply -f FILENAME [flags]
. Apply a configuration change to a resource from a file or stdin. Allows to create a Pod.
- Attach
kubectl attach POD -c CONTAINER [-i] [-t] [flags]
:Attach to a running container either to view the output stream or interact with the container (stdin)
- Auto Scale
kubectl autoscale (-f FILENAME \| TYPE NAME \| TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [flags]
: Automatically scale the set of pods that are managed by a replication controller
- Cluster Info
kubectl cluster-info [flags]
:Display endpoint information about the master and services in the cluster
- Create
kubectl create -f FILENAME [flags]
: Create one or more resources from a file or stdinkubectl create namespace myexamplenamespace
kubectl create sa my_new_user
(Create service account for your my_new_user)kubectl create -f mypod.yaml
- Config:
kubectl config .../...
- Delete
kubectl delete (-f FILENAME \| TYPE [NAME \| /NAME \| -l label \| --all]) [flags]
:Delete resourceskubectl delete --all namespaces
- Describe
kubectl describe (-f FILENAME \| TYPE [NAME_PREFIX \| /NAME \| -l label]) [flags]
: Detailed state of one or more resources.kubectl describe pod MyPodName
kubectl describe pods
kubectl describe replicaset MyReplicaName
- Edit
kubectl edit (-f FILENAME \| TYPE NAME \| TYPE/NAME) [flags]
: Edit and update the definition of one or more resources on the server by using the default editor.
- Execute
kubectl exec POD [-c CONTAINER] [-i] [-t] [flags] [-- COMMAND [args...]]
: Execute a command against a container in a pod
- Logs
kubectl logs POD [-c CONTAINER] [--follow] [flags]
: Print the logs for a container in a pod.kubectl logs -l app=elasticsearch
(using labels: -l)
- Get:
- Replace:
kubectl replace --force -f yml_file_describing_pod.yml
- Proxy:
kubectl proxy --port=8080
[3]
- Rolling-update:
kubectl rolling-update
- Run
kubectl run NAME --image=image [--env="key=value"] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [flags]
: Run a specified image on the cluster.
- Scale:
kubectl scale deployment YOUR_DEPLOYMENT_NAME
- Stop
kubectl stop
- Version
kubectl version [--client] [flags]
: Display the Kubernetes version running on the client and server.
Activities[edit]
- Create and configure a basic Pod (
kubectl apply
) - Read official
kubectl
cheat sheet: https://kubernetes.io/docs/reference/kubectl/cheatsheet/ - Check examples: https://www.codegrepper.com/code-examples/shell/kubectl+describe+ingress+output+yaml
- https://stackoverflow.com/questions/tagged/kubectl?tab=Votes
- Kubernetes quiz
- Merge multiple kubeconfigs:
~/.kube/configs
into one usingkubectl konfig merge
Related[edit]
- Krew
kops
- Kots kubectl plugin
- K9s
aws eks --region $(terraform output -raw region) update-kubeconfig --name $(terraform output -raw cluster_name)
kubectl-convert
kubeadm
Error: flags cannot be place before plugin name
kubectl.kubernetes.io
- kubectl (alias)
- Terraform: kubectl provider
kubectl --request-timeout
See also[edit]
- Kubernetes Components,
kube-proxy, kube-scheduler, kube-apiserver, kubelet, kubectl, kubeadm
, Kubernetes controller manager, Kubernetes controllers, Kubernetes Addons, Kubernetes Topology Manager kubectl
: [cp | config | create
|delete
|edit | explain |
apply
|exec
|get
|set
|drain | uncordon | rolling-update
|rollout
|logs
|run
|auth
|label | annotate
|version
|top
|diff
|debug
|replace
|describe
|port-forward | proxy
|scale
|rollout
|api-resources
| expose deployment | expose | patch | attach | get endpoints | ~/.kube/config | kubectl logs --help | kubectl --help, kubectl-convert, kubectl autoscale, kubectl.kubernetes.io
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy.
Source: https://en.wikiversity.org/wiki/DevOps/Kubernetes/kubectl
Advertising: