Editing Kubectl
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | + | <code>kubectl</code> is a command line interface for running commands against [[Kubernetes]] clusters.<ref>https://kubernetes.io/docs/reference/kubectl/overview/</ref> | |
− | <code> | ||
− | + | To install in MacOS execute: <code>brew install kubernetes-cli</code> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | == | + | == kubectl info commands == |
− | * | + | * Verify running [[Pod]]s: |
− | + | ** <code>kubectl get pods</code> | |
− | + | ** <code>kubectl get pod PODNAME</code> | |
− | + | ** <code>kubectl get pod PODNAME -n MY_NAMESPACE</code> | |
− | + | ** <code>kubectl get pod PODNAME -n MY_NAMESPACE --watch</code> | |
− | + | * Fetch metrics for PODNAME pod <code>kubectl top pod PODNAME</code> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | * | ||
− | * <code> | ||
− | * | ||
− | * <code> | ||
− | * | ||
− | * <code> | ||
− | * | ||
− | * <code> | ||
− | |||
− | |||
− | |||
− | * <code> | ||
− | |||
− | |||
− | == | + | == kubectl operation commands == |
− | + | * Connect to a Pod: <code>kubectl exec -it YOUR_POD_NANE -- /bin/bash</code> | |
− | == kubectl | + | == kubectl delete/destroy commands == |
− | * <code> | + | * <code>kubectl delete namespace MY_NAMESPACE</code> |
− | |||
− | |||
− | |||
− | == kubectl | + | == kubectl Command Reference == |
The following table includes short descriptions and the general syntax for all of the <code>kubectl</code> operations:<ref>https://kubernetes.io/docs/reference/kubectl/overview/</ref> | The following table includes short descriptions and the general syntax for all of the <code>kubectl</code> operations:<ref>https://kubernetes.io/docs/reference/kubectl/overview/</ref> | ||
− | *'''Apply''' <code> | + | *'''Apply''' <code>kubectl apply -f FILENAME [flags]</code>. Apply a configuration change to a resource from a file or stdin. Allows to [[create a Pod]]. |
*'''Attach''' <code>kubectl attach POD -c CONTAINER [-i] [-t] [flags]</code>:Attach to a running container either to view the output stream or interact with the container (stdin) | *'''Attach''' <code>kubectl attach POD -c CONTAINER [-i] [-t] [flags]</code>:Attach to a running container either to view the output stream or interact with the container (stdin) | ||
Line 59: | Line 27: | ||
− | *'''Cluster Info''' <code> | + | *'''Cluster Info''' <code>kubectl cluster-info [flags]</code> :Display endpoint information about the master and services in the cluster |
− | *'''Create''' <code> | + | *'''Create''' <code>kubectl create -f FILENAME [flags]</code>: Create one or more resources from a file or stdin |
** <code>kubectl create namespace myexamplenamespace</code> | ** <code>kubectl create namespace myexamplenamespace</code> | ||
** <code>kubectl create sa my_new_user</code> (Create service account for your my_new_user) | ** <code>kubectl create sa my_new_user</code> (Create service account for your my_new_user) | ||
Line 68: | Line 36: | ||
*'''Config''': <code>kubectl config .../...</code> | *'''Config''': <code>kubectl config .../...</code> | ||
− | ** <code> | + | ** <code>kubectl config view</code> |
*'''Delete''' <code>kubectl delete (-f FILENAME \| TYPE [NAME \| /NAME \| -l label \| --all]) [flags]</code> :Delete resources | *'''Delete''' <code>kubectl delete (-f FILENAME \| TYPE [NAME \| /NAME \| -l label \| --all]) [flags]</code> :Delete resources | ||
Line 85: | Line 53: | ||
** <code>kubectl logs -l app=elasticsearch</code> (using labels: -l) | ** <code>kubectl logs -l app=elasticsearch</code> (using labels: -l) | ||
− | * ''' | + | * '''Get''': |
+ | ** <code>kubectl get apiservices</code> | ||
+ | ** <code>kubectl get nodes</code> | ||
+ | ** <code>kubectl get pods</code> | ||
+ | ** <code>kubectl get pod PODNAME -n NAMESPACE -o yaml | kubectl replace --force -f -</code><ref>https://stackoverflow.com/a/45046340/9269906</ref> | ||
− | * '''Replace''': <code> | + | * '''Replace''': <code>kubectl replace --force -f yml_file_describing_pod.yml</code> |
− | * '''Proxy''': <code> | + | * '''Proxy''': <code>kubectl proxy --port=8080</code><ref>https://kubernetes.io/docs/tasks/access-kubernetes-api/http-proxy-access-api/</ref> |
− | * '''Rolling-update:''' <code> | + | * '''Rolling-update:''' <code>kubectl rolling-update</code> |
− | *'''Run''' <code> | + | *'''Run''' <code>kubectl run NAME --image=image [--env="key=value"] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [flags]</code>: Run a specified image on the cluster. |
− | *'''Scale''': <code> | + | *'''Scale''': <code>kubectl scale deployment YOUR_DEPLOYMENT_NAME</code> |
*'''Stop''' <code>kubectl stop</code> | *'''Stop''' <code>kubectl stop</code> | ||
Line 101: | Line 73: | ||
*'''Version''' <code>kubectl version [--client] [flags]</code>: Display the Kubernetes version running on the client and server. | *'''Version''' <code>kubectl version [--client] [flags]</code>: Display the Kubernetes version running on the client and server. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | == | + | == See also == |
− | * | + | * {{k8s}} |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | [[Category: Software development]] | |
− | + | [[Category:Server administration]] | |
− | |||
− | |||
− | |||
{{CC license}} | {{CC license}} | ||
Source: https://en.wikiversity.org/wiki/DevOps/Kubernetes/kubectl | Source: https://en.wikiversity.org/wiki/DevOps/Kubernetes/kubectl |
Advertising: