prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Delete the pods and services with the names "log-aggregator" and "foo"
Command: ```bash kubectl delete pod,service log-aggregator foo ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label select...
Create a new LoadBalancer service named 'payment-gateway-lb' that will forward traffic from port 9000 externally to port 8082 internally.
Command: ```bash kubectl create service loadbalancer payment-gateway-lb --tcp=9000:8082 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", ...
Forward traffic from port 5000 on all addresses to port 8888 inside the 'analytics-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 5000:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Create an ingress called 'website-ingress' that directs requests to website.com/bar to svc1:8080 using the tls secret "my-cert"
Command: ```bash kubectl create ingress website-ingress --rule="website.com/bar=svc1:8080,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ file from the local machine to the /tmp/bar directory in a remote pod named monitoring-agent-pod-6, in the cert-manager namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ cert-manager/monitoring-agent-pod-6:/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage...
Auto scale the replication controller "vpn" with a target CPU utilization of 20%. Set the maximum number of pods to 3.
Command: ```bash kubectl autoscale rc vpn --max=3 --cpu-percent=20 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Forward local port 8088 to port 9090 in a selected pod from the "database-deployment" deployment.
Command: ```bash kubectl port-forward deployment/database-deployment 8088 9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Set the resource requests and limits for all containers in the 'amazonlinux' deployment
Command: ```bash kubectl set resources deployment amazonlinux --limits=cpu=200m,memory=512Mi --requests=cpu=3,memory=64Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requ...
Create a deployment named logging with the amazonlinux image and 2 replicas.
Command: ```bash kubectl create deployment logging --image=amazonlinux --replicas=2 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. On...
List deployments in JSON format in the "alpha-2.0" version of the "legacy-apps" API group.
Command: ```bash kubectl get deployments.alpha-2.0.legacy-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you ...
Update the annotation 'alert-email' for the pod 'api', setting the value to 'alerts@example.com' and overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods api alert-email='alerts@example.com' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels a...
Update the environment variable 'MAX_CONNECTIONS' for deployment 'cache-cluster-deployment'
Command: ```bash kubectl set env deployment/cache-cluster-deployment MAX_CONNECTIONS=100 ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templ...
Update the image of a container in a pod using a JSON patch command
Command: ```bash kubectl patch pod monitoring-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (...
Stream the logs of the "cyber-sleuth" container in the "backend-pod" pod.
Command: ```bash kubectl logs -f -c cyber-sleuth backend-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "sho...
Configure autoscaling for the "backend" deployment with a minimum of 1 pod and a maximum of 9 pods.
Command: ```bash kubectl autoscale deployment backend --min=1 --max=9 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses ...
Create a service for a replicated Wordpress using replica set, serving on port 3001 and connecting to the containers on port 300100
Command: ```bash kubectl expose rs wordpress --port=3001 --target-port=300100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Create a pod disruption budget named statefulset-pdb that selects all pods with the env=production label and requires a minimum of four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget statefulset-pdb --selector=env=production --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N...
Set up autoscaling for the deployment 'analytics' with a minimum of 2 pods and a maximum of 10 pods.
Command: ```bash kubectl autoscale deployment analytics --min=2 --max=10 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that us...
Update the annotation 'contact-email' of pod 'database' with the value 'support@example.com'
Command: ```bash kubectl annotate --overwrite pods database contact-email='support@example.com' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than ...
Copy a directory from a remote pod to a local directory
Command: ```bash kubectl cp kubeapps/cache-pod-5:/tmp/foo_dir /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.k...
Add a taint with key 'cpu-type' on nodes having label team=devops
Command: ```bash kubectl taint node -l team=devops cpu-type=edge-node-10:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Display the replication controller named 'web', the service named 'e-commerce-rc', and the pod named 'database-pod'
Command: ```bash kubectl get rc/web service/e-commerce-rc pods/database-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced...
Return snapshot logs from the container 'backend-microservice-deployment-1' of the deployment named 'api-service-pod'.
Command: ```bash kubectl logs deployment/backend-microservice-deployment -c api-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful f...
Create a job named "log-collection" using the "busybox" image.
Command: ```bash kubectl create job log-collection --image=busybox ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: jso...
Create a new config map named 'app-name-config' using the specified files as keys
Command: ```bash kubectl create configmap app-name-config --from-file=properties=/path/to/settings/file1.txt --from-file=key1=/path/to/settings/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creat...
Open and edit a service using Sublime as the editor
Command: ```bash KUBE_EDITOR="sublime" kubectl edit svc/analytics-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment vari...
Forward traffic from port 5000 on all addresses to port 8000 in the 'mypod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 5000:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be sel...
Create a new secret named 'azure-storage-secret' with key/value pairs for each file in the 'path/to/profiles' folder
Command: ```bash kubectl create secret generic azure-storage-secret --from-file=path/to/profiles ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basenam...
Create an autoscaler for the 'log-aggregator' replication controller with a maximum of 5 pods and a target CPU utilization of 81%
Command: ```bash kubectl autoscale rc log-aggregator --max=5 --cpu-percent=81 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler th...
Create a service for the replication controller specified in "wordpress-controller.yaml", serving on port 8181 and connecting to the containers on port 888800.
Command: ```bash kubectl expose -f wordpress-controller.yaml --port=8181 --target-port=888800 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on ...
create a new pod named "hazelcast" using the "redis" image and expose port 9000
Command: ```bash kubectl run hazelcast --image=redis --port=9000 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--fi...
Return the logs of the previous terminated rocket-ranger container from the pod api-service-pod
Command: ```bash kubectl logs -p -c rocket-ranger api-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container",...
Auto scale the replication controller "media-stream" to have a minimum of 1 pod and a maximum of 8 pods, with a target CPU utilization of 60%.
Command: ```bash kubectl autoscale rc media-stream --max=8 --cpu-percent=60 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that...
Start a Jenkins pod with a specific image, but override some of the specifications using a JSON file.
Command: ```bash kubectl run nginx --image=jenkins --overrides='{ "apiVersion": "v1.1.1", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMA...
Configure custom TLS server name for the moon-cluster cluster entry
Command: ```bash kubectl config set-cluster moon-cluster --tls-server-name=data-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate...
Import the specific key "CONFIG_FILE_PATH" from the config map "ui-config" and apply it to the deployment "web-app-deployment"
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/ui-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Remove the user 'admin' from the kubectl configuration
Command: ```bash kubectl config delete-user admin ``` What it does: Delete the specified user from the kubeconfig. Syntax: `kubectl config delete-user NAME`
create a cron job that runs a command at a specified schedule
Command: ```bash kubectl create cronjob report-generation --image=busybox --schedule="*/1 * * * *" ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "defaul...
Create a job named "report-generation-job" using the python image and execute the command "python" within the job
Command: ```bash kubectl create job report-generation-job --image=python -- python ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output for...
Update the annotation 'team' of the 'proxy-server' pod with the value 'frontend-team', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods proxy-server team='frontend-team' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and ...
Create a new secret named azure-storage-secret from an environment file.
Command: ```bash kubectl create secret generic azure-storage-secret --from-env-file=path/to/preferences.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to ...
Retrieve the output of the 'php --version' command from the warp-drive container in the e-commerce-pod pod.
Command: ```bash kubectl exec e-commerce-pod -c warp-drive -- php --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted...
Create a service for the replicated WordPress using a replica set
Command: ```bash kubectl expose rs wordpress --port=6379 --target-port=909000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
View the resource usage metrics for pods labeled with "myLabel"
Command: ```bash kubectl top pod -l myLabel ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl top pod [NAME | -l labe...
Add release notes to a pod defined in the "docker-registry.yaml" file
Command: ```bash kubectl annotate -f docker-registry.yaml release-notes='https://example.com/release-notes/v2.5.1' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that ...
Fetch the snapshot logs from the first container of the 'cache-warming-job' job.
Command: ```bash kubectl logs job/cache-warming-job ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c"...
Scale the deployment named prod-app-rs to 3 replicas, if its current size is 5
Command: ```bash kubectl scale --current-replicas=5 --replicas=3 deployment/prod-app-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version...
Return the snapshot of the previous terminated 'nebula-navigator' container logs from the 'api-service-pod' pod.
Command: ```bash kubectl logs -p -c nebula-navigator api-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--containe...
Copy the contents of "/var/run/secrets/kubernetes.io/serviceaccount/" from the remote pod "rook-ceph/logging-agent-pod-7" to the local directory "/tmp/bar".
Command: ```bash kubectl cp rook-ceph/logging-agent-pod-7:/var/run/secrets/kubernetes.io/serviceaccount/ :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "C...
Create a new ExternalName service named external-git-service that points to the DNS record museum-example.museum
Command: ```bash kubectl create service externalname external-git-service --external-name museum-example.museum ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference se...
Create a secret named private-key-secret from an environment file
Command: ```bash kubectl create secret generic private-key-secret --from-env-file=path/to/properties.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the...
Forward local port 5432 to port 5000 in the pod named mypod
Command: ```bash kubectl port-forward pod/mypod 5432:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Create a new secret named jwt-secret by using the values from the environment file located at path/to/settings.env.
Command: ```bash kubectl create secret generic jwt-secret --from-env-file=path/to/settings.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basename ...
Retrieve the snapshot logs from the 'payment-gateway-pod' pod, including logs from all containers within the pod.
Command: ```bash kubectl logs payment-gateway-pod --all-containers=true ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--conta...
Update the annotation value for a pod named 'vpn' with the key 'description' and the value 'Web server for marketing site', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods vpn description='Web server for marketing site' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger th...
Create a service for the replicated Wordpress using a replica set
Command: ```bash kubectl expose rs wordpress --port=3000 --target-port=330600 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Listen on localhost port 8081 and forward the traffic to port 9090 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward pod/frontend-pod 8081:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Enable autoscaling for the 'gateway' replication controller with a maximum of 3 pods and a target CPU utilization of 40%
Command: ```bash kubectl autoscale rc gateway --max=3 --cpu-percent=40 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses...
Retrieve the output from running the 'geth' command in the default container of the 'gateway-pod' pod.
Command: ```bash kubectl exec gateway-pod -- geth ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kubernet...
Execute the 'php --version' command inside the nano-bot container of the analytics-pod pod.
Command: ```bash kubectl exec analytics-pod -c nano-bot -- php --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
delete the pods and services with the names "database" and "gateway"
Command: ```bash kubectl delete pod,service database gateway ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector...
Create a copy of the proxy-service-pod named "debug-image-web", and change all container images in the copied pod to "docker.elastic.co/elasticsearch/elasticsearch".
Command: ```bash kubectl debug proxy-service-pod --copy-to=debug-image-web --set-image=*=docker.elastic.co/elasticsearch/elasticsearch ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and ...
Create a cluster role named "reader" with a NonResourceURL specified as "/readyz" and allowed verb as "proxy"
Command: ```bash kubectl create clusterrole "reader" --verb=proxy --non-resource-url=/readyz ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short...
Remove the "client-secret" config value for the OpenID Connect auth provider for the "admin" entry.
Command: ```bash kubectl config set-credentials admin --auth-provider=oidc --auth-provider-arg=client-secret- ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=k...
Create an ingress called 'myapp-ingress' that directs requests from testing.com/bar to a service called svc1 running on port 3306, and use the TLS secret "my-cert"
Command: ```bash kubectl create ingress myapp-ingress --rule="testing.com/bar=svc1:3306,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/ui-config deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Define new exec auth plugin arguments for the "jane.smith" entry, using arg1 and arg2 as the arguments.
Command: ```bash kubectl config set-credentials jane.smith --exec-arg=arg1 --exec-arg=arg2 ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=keyfile Bearer token...
Execute the command 'yum install -y aws-cli' inside a container named 'warp-drive' in the pod 'cdn-service-pod'.
Command: ```bash kubectl exec cdn-service-pod -c warp-drive -- yum install -y aws-cli ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. ...
Create an ingress called 'myapp-ingress' with the following rule: directing requests to 'testing.com/input' to 'svc1:8081' with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress myapp-ingress --rule="testing.com/input=svc1:8081,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Add a taint with key 'app' on nodes having label version=v1.0.0
Command: ```bash kubectl taint node -l version=v1.0.0 app=backup-node-14:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Create a service for the replicated alpine using the replica set, which serves on port 8443 and connects to the containers on port 543200.
Command: ```bash kubectl expose rs alpine --port=8443 --target-port=543200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Set the annotation 'security-scan-status' to 'pass' for the pod named 'frontend'
Command: ```bash kubectl annotate pods frontend security-scan-status=pass ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arb...
Forward traffic from port 8000 on localhost and IP 10.19.21.23 to port 5432 in the pod named "analytics-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8000:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the crite...
Create a cron job named data-processing using the busybox image and scheduling it to run every minute.
Command: ```bash kubectl create cronjob data-processing --image=busybox --schedule="*/1 * * * *" ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default"...
Set the cluster field for a specific context
Command: ```bash kubectl config set contexts.app-2-context.cluster galaxy-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you ...
Create a pod disruption budget named auth-service-pdb that will select all pods with the tier=frontend label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget auth-service-pdb --selector=tier=frontend --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N...
Update the label of the pod 'auth' by adding the label 'component' with the value 'web'.
Command: ```bash kubectl label pods auth component=web ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If...
List deployments with the JSON output format in the "alpha-2.0" version of the "extensions" API group
Command: ```bash kubectl get deployments.alpha-2.0.extensions -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you w...
Copy a file from a remote pod to a local directory
Command: ```bash kubectl cp istio-system/auth-service-pod-11::/tmp/foo /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Add a taint with key 'workload' on nodes having label myLabel
Command: ```bash kubectl taint node -l myLabel workload=edge-node-10:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outpu...
Create a resource quota named secret-quota with a limit of 10 secrets
Command: ```bash kubectl create quota secret-quota --hard=secrets=10 ``` What it does: Create a resource quota with the specified name, hard limits, and optional scopes. Syntax: `kubectl create quota NAME [--hard=key1=value1,key2=value2] [--scopes=Scope1,Scope2] [--dry-run=server|client|none]` Helpful flags: "flag":...
Get the output of the 'php --version' command from the astro-container in the security-service-pod
Command: ```bash kubectl exec security-service-pod -c astro-container -- php --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name....
Update the annotation 'scaling-policy' with the value 'auto-horizontal-scaling' for the pod named 'chat-app', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods chat-app scaling-policy='auto-horizontal-scaling' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger ...
Create a new ExternalName service with the name "external-database-service" that points to the external DNS name "news-demo.news"
Command: ```bash kubectl create service externalname external-database-service --external-name news-demo.news ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference serv...
Forward incoming traffic from local port 8000 to port 8000 in the backend-pod, and forward outgoing traffic from the backend-pod on port 6000 to local port 6000.
Command: ```bash kubectl port-forward pod/backend-pod 8000 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Embed the certificate authority data for the edge-cluster cluster entry.
Command: ```bash kubectl config set-cluster edge-cluster --embed-certs --certificate-authority=~/.kube/cluster-beta/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set...
Display the most recent 23 lines of logs for the pod named proxy-server-pod.
Command: ```bash kubectl logs --tail=23 proxy-server-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short":...
Create a job called "image-build-job" using the "jenkins" image and run the command "jenkins --version" within the job
Command: ```bash kubectl create job image-build-job --image=jenkins -- jenkins --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outp...
Add a taint with the key 'disktype' on nodes having the label 'version=v1.0.0', specifically on the node-1 with the preference of not scheduling any new pods on it.
Command: ```bash kubectl taint node -l version=v1.0.0 disktype=node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outp...
Create an ingress named 'default-ingress' that routes requests from site.com/example to svc1:8088
Command: ```bash kubectl create ingress default-ingress --rule="site.com/example=svc1:8088,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Start streaming the logs of the warp-drive container in the cdn-service-pod pod
Command: ```bash kubectl logs -f -c warp-drive cdn-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "s...
Create a job named "testing" using the nginx image and run the command "nginx -t" within the job.
Command: ```bash kubectl create job testing --image=nginx -- nginx -t ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: ...
Expose the replication controller "nginx" as a service on port 80, connecting to the containers on port 8000.
Command: ```bash kubectl expose rc nginx --port=80 --target-port=808000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A ...
Forward port 9090 locally to port 6379 in the pod "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 9090:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected auto...
Scale the deployment named "webapp-replicaset" to 5 replicas if its current size is 1.
Command: ```bash kubectl scale --current-replicas=1 --replicas=5 deployment/webapp-replicaset ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-v...
Set the resource request and limits for all containers in the "kafka" deployment
Command: ```bash kubectl set resources deployment kafka --limits=cpu=200m,memory=512Mi --requests=cpu=500m,memory=1Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requeste...
Create a copy of the backend-pod, adding a debug container, and changing the container images
Command: ```bash kubectl debug backend-pod -it --copy-to=debug-image-app --image=debian --set-image=logger=logging-app:debug,web=nginx:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resour...
Update the label of a pod to specify its role as 'frontend'
Command: ```bash kubectl label pods proxy-server role=frontend ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usa...
Add or update the annotation 'git-repo' for the pod 'chat-app' with the value 'https://github.com/example/my-app'
Command: ```bash kubectl annotate --overwrite pods chat-app git-repo='https://github.com/example/my-app' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be lar...
Add a taint with the key 'cpu-type' on nodes having the label feature=feature-xyz.
Command: ```bash kubectl taint node -l feature=feature-xyz cpu-type=edge-node-10:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...