Difference between revisions of "Kubectl"
Jump to navigation
Jump to search
Line 20: | Line 20: | ||
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>kubectl apply -f FILENAME [flags]</code>. Apply a configuration change to a resource from a file or stdin. Allows to [[Create and configure a basic Pod | + | *'''Apply''' <code>kubectl apply -f FILENAME [flags]</code>. Apply a configuration change to a resource from a file or stdin. Allows to [[Create and configure a basic Pod|create a Pod]]. |
− | |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) |
Revision as of 18:54, 6 January 2020
kubectl
is a command line interface for running commands against Kubernetes clusters.[1]
To install in MacOS execute: brew install kubernetes-cli
Contents
kubectl info commands
- Verify running Pods:
kubectl get pods
kubectl get pod PODNAME
kubectl get pod PODNAME -n MY_NAMESPACE
kubectl get pod PODNAME -n MY_NAMESPACE --watch
- Fetch metrics for PODNAME pod
kubectl top pod PODNAME
kubectl operation commands
- Connect to a Pod:
kubectl exec -it YOUR_POD_NANE -- /bin/bash
kubectl delete/destroy commands
kubectl delete namespace MY_NAMESPACE
kubectl command reference
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 .../...
kubectl config view
- 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:
kubectl get apiservices
kubectl get nodes
kubectl get pods
kubectl get pod PODNAME -n NAMESPACE -o yaml | kubectl replace --force -f -
[3]
- Replace:
kubectl replace --force -f yml_file_describing_pod.yml
- Proxy:
kubectl proxy --port=8080
[4]
- 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.
See also
- Kubernetes: distributions, tools, CKA, CKS, Kubernetes interfaces: CSI, CNI, installation, workloads, networking,
kubeadm
,Kubernetes API
, Kubernetes API Server,kubectl, kubeadm, kubelet, kube-proxy
, Cloud services: EKS, GKE, TKE, DKS, Helm, Kubernetes RBAC, Kubernetes deployments, Minikube, Rancher, OpenShift, Charmed Kubernetes, Ingress, Kubernetes scheduler, Kubernetes Finalizers, logging, Kubernetes operator, Orka,kind:
, Kubernetes namespaces, Kubernetes dashboard, Kubernetes Metrics Server, Field Selectors, CoreDNS, CRI, Kubernetes Topology Manager, Kubernetes governance: (SIG, KEP), Kustomize, controllers,ReadinessProbe, LivenessProbe
, KOPS, K9s, Kui, k3s, ImagePullBackOff, PDB, EndPoints, Kots, metadata, Karpenter, Replicated.com, Kubernetes Authenticating, Kubernetes timeline, Changelog/Versions, service accounts, Kubernetes Pod Lifecycle, Kubernetes Conformance Certified, Kubernetes backup, Kubernetes Pod Security Admission, tEKS, Kubernetes events, Kubernetes ports, Kubernetes policies, Connect, addons, DoKC, Kubernetes control plane, Kubernetes Federation, Kubernetes info, Kubetest2, Sidecar (Kubernetes)
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: