prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a new config map named app-config-dev with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap app-config-dev --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/path/to/options/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 cre...
Create a new ExternalName service named 'external-third-party-api-service' with the external name 'education-edu.edu'
Command: ```bash kubectl create service externalname external-third-party-api-service --external-name education-edu.edu ``` 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 refe...
remove the taint with the key 'cpu-type' and effect 'NoSchedule' from the node 'worker-node-3'
Command: ```bash kubectl taint nodes worker-node-3 cpu-type:NoSchedule- ``` 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": "Output format. One o...
Update the annotation "last-deployment" of the pod identified by type and name in the "config.json" file and set it to "2023-03-15".
Command: ```bash kubectl annotate -f config.json last-deployment=2023-03-15 ``` 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 a...
Unset the namespace for the client-1-context context
Command: ```bash kubectl config unset contexts.client-1-context.namespace ``` What it does: Unset 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. Syntax: `kubectl config unset PROPERTY_NA...
Delete the pods and services with the names "proxy-server" and "proxy".
Command: ```bash kubectl delete pod,service proxy-server proxy ``` 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...
Set the custom TLS server name to be used for validation for the 'cloud-cluster' cluster entry as 'testing-cluster'.
Command: ```bash kubectl config set-cluster cloud-cluster --tls-server-name=testing-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] [--certifi...
Forward traffic from port 5000 on localhost and the IP address 10.19.21.23 to port 8081 in the e-commerce-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 5000:8081 ``` 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 crit...
Forward port 8081 on localhost and IP address 10.19.21.23 to port 8000 in the cdn-service-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 8081: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 cri...
Forward local port 8088 to pod port 8081
Command: ```bash kubectl port-forward pod/web-app-pod 8088:8081 ``` 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...
Copy the file /tmp/foo from the load-balancer-pod-9 pod to the local machine's /tmp/bar directory
Command: ```bash kubectl cp monitoring/load-balancer-pod-9:/tmp/foo /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 kub...
Create a new ExternalName service named external-database-service pointing to the external name test-site.org
Command: ```bash kubectl create service externalname external-database-service --external-name test-site.org ``` 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 servi...
Create a pod disruption budget named batch-processing-pdb that will select all pods with the owner=team-1 label and require a minimum of one of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget batch-processing-pdb --selector=owner=team-1 --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-availabl...
Forward local traffic from port 8000 to port 8081 in a pod selected by the deployment "authentication-service-deployment"
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 8000 8081 ``` 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, ...
Create a cluster role named "bar" with permissions to list ConfigMaps and access specific resource names.
Command: ```bash kubectl create clusterrole bar --verb=list --resource=configmaps --resource-name=dev-database --resource-name=blog-backend ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|no...
Create a copy of the "database-pod" with all container images changed to "mongo"
Command: ```bash kubectl debug database-pod --copy-to=debug-image-1 --set-image=*=mongo ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resour...
Import specific keys from a config map for a deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/kube-system-config deployment/log-aggregator-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 d...
Create an ingress called 'private-service-ingress' that directs requests to website.com/example to svc1:9000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="website.com/example=svc1:9000,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...
Update the image of the container named "kubernetes-serve-hostname" in the frontend-pod. Set the new image as "new image".
Command: ```bash kubectl patch pod frontend-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"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 (-f FILENAM...
Auto scale the replication controller "vpn" with the number of pods set between 1 and 4, targeting a CPU utilization of 20%.
Command: ```bash kubectl autoscale rc vpn --max=4 --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...
Import specific keys from a config map to a deployment named "search-engine-deployment".
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/ui-config deployment/search-engine-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...
Get the output from running the 'mysqld' command in the 'cyber-sleuth' container of the 'web-app-pod' pod.
Command: ```bash kubectl exec web-app-pod -c cyber-sleuth -- mysqld ``` 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 th...
Retrieve the output from running the `dotnet --list-runtimes` command in the `rocket-ranger` container within the `cdn-service-pod` pod.
Command: ```bash kubectl exec cdn-service-pod -c rocket-ranger -- dotnet --list-runtimes ``` 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 nam...
Update the environment variables of the "notification-handler-deployment" deployment, importing only the "my-example-key" key from the "app-config-dev" config map.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-config-dev deployment/notification-handler-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 vari...
Create a role named "view" with specified resources and verbs
Command: ```bash kubectl create role view --verb=watch --resource=pods --resource-name=load-balancer --resource-name=app-worker-1 ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|clien...
Copy the ~/.config/kube local file to /tmp/bar directory in the worker-pod-4 pod in the kube-node-lease namespace.
Command: ```bash kubectl cp ~/.config/kube kube-node-lease/worker-pod-4:/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...
Retrieve the deployments in the "custom-version" version of the "external-apps" API group and display them in YAML format.
Command: ```bash kubectl get deployments.custom-version.external-apps -o yaml ``` 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 namespac...
Get the output of the command 'docker run ubuntu echo "Hello, World"' executed in the 'quantum-quark' container of the 'frontend-pod' pod.
Command: ```bash kubectl exec frontend-pod -c quantum-quark -- docker run ubuntu echo "Hello, World" ``` 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": "C...
Execute the 'geth version' command in the quantum-quark container from the database-pod pod, and retrieve the output.
Command: ```bash kubectl exec database-pod -c quantum-quark -- geth 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...
Set the custom TLS server name to 'kube-cluster-2' for the 'on-prem-cluster' cluster entry
Command: ```bash kubectl config set-cluster on-prem-cluster --tls-server-name=kube-cluster-2 ``` 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] [--certif...
Update the pod 'api' by setting the annotation 'SLA' to '99.9% uptime'.
Command: ```bash kubectl annotate pods api SLA='99.9% uptime' ``` 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 arbitrary strin...
Create a copy of a pod with a debug container and modified container images
Command: ```bash kubectl debug backend-pod -it --copy-to=debug-image-web --image=debian --set-image=cache=redis:alpine,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource a...
Create a cron job named "daily-report" that runs the "ash" command every minute using the Alpine image.
Command: ```bash kubectl create cronjob daily-report --image=alpine --schedule="*/1 * * * *" -- ash ``` 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", "defau...
Forward traffic from port 5432 on all addresses to port 8888 in the pod "e-commerce-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 5432: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 wi...
Create a new config map named api-config with the specified keys and their respective file paths
Command: ```bash kubectl create configmap api-config --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/path/to/data/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 creating a...
create a service for a replicated nginx, serving on port 80 and connecting to the containers on port 8000
Command: ```bash kubectl expose rc nginx --port=5001 --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 service account of the 'user-management-deployment' deployment to 'dashboard'
Command: ```bash kubectl set serviceaccount deployment user-management-deployment dashboard ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `...
Create a job named 'scaling-job' with the 'nginx' image, and run the 'nginx -t' command
Command: ```bash kubectl create job scaling-job --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 ...
Retrieve the output of the `dotnet --list-sdks` command running inside the `cosmic-container` container of the `database-pod` pod
Command: ```bash kubectl exec database-pod -c cosmic-container -- dotnet --list-sdks ``` 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. I...
Deny a certificate signing request with the name 'csr-ingress-7'
Command: ```bash kubectl certificate deny csr-ingress-7 ``` What it does: Deny a certificate signing request. kubectl certificate deny allows a cluster admin to deny a certificate signing request (CSR). This action tells a certificate signing controller to not to issue a certificate to the requestor. Syntax: `kubectl...
Create an ingress resource named 'website-ingress' with a rule that directs requests for testing.com/bar to the service 'svc1' on port 5001
Command: ```bash kubectl create ingress website-ingress --rule="testing.com/bar=svc1:5001,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...
Create a new secret named ldap-credentials-secret from an environment file
Command: ```bash kubectl create secret generic ldap-credentials-secret --from-env-file=path/to/data.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 ...
Change the service account of the deployment named "analytics-platform-deployment" to "spinnaker"
Command: ```bash kubectl set serviceaccount deployment analytics-platform-deployment spinnaker ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax...
Update the annotation value of the pod 'security' with the annotation key 'compliance-level' to 'PCI-DSS', and overwrite any existing value
Command: ```bash kubectl annotate --overwrite pods security compliance-level='PCI-DSS' ``` 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 an...
Create a debug pod named 'my-debugger' by making a copy of the 'web-app-pod' pod, and launch an interactive shell in the 'rocket-ranger' container inside the debug pod.
Command: ```bash kubectl debug web-app-pod -it --copy-to=my-debugger --container=rocket-ranger -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default...
Return the logs of a previously terminated container named "time-machine" from the pod "vpn-service-pod"
Command: ```bash kubectl logs -p -c time-machine vpn-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", ...
Add a taint with the key 'dedicated' and the value 'k8s-node-1:PreferNoSchedule' on nodes having the label 'release=beta'
Command: ```bash kubectl taint node -l release=beta dedicated=k8s-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": "O...
Set the resource request and limits for all containers in the elasticsearch deployment to a CPU limit of 200m, memory limit of 512Mi, CPU request of 10, and memory request of 4Gi.
Command: ```bash kubectl set resources deployment elasticsearch --limits=cpu=200m,memory=512Mi --requests=cpu=10,memory=4Gi ``` 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 re...
Show the differences between the resources included in the config.json file and the resources currently applied in the cluster
Command: ```bash kubectl diff -f config.json ``` What it does: Diff configurations specified by file name or stdin between the current online configuration, and the configuration as it would be if applied. The output is always YAML. KUBECTL_EXTERNAL_DIFF environment variable can be used to select your own diff command...
start a pod named nginx with the ruby image, but use the specified JSON overrides to set some of the pod's spec values
Command: ```bash kubectl run nginx --image=ruby --overrides='{ "apiVersion": "rc-1.1.0", "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] -- [COMMAN...
Create a cluster role named "view" with the ResourceName specified as "backup-service" and "dashboard-ui"
Command: ```bash kubectl create clusterrole view --verb=get --resource=pods --resource-name=backup-service --resource-name=dashboard-ui ``` 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]`...
Import the 'config_file_path' key from the 'monitoring-config' config map and set it as an environment variable for the 'api-server-deployment' deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/monitoring-config deployment/api-server-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 ...
Expose the php-controller replication controller using the specifications provided in the 'php-controller.yaml' file
Command: ```bash kubectl expose -f php-controller.yaml --port=5000 --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 sp...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/ui-config deployment/search-engine-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...
Create a cluster role named "view" with SubResource specified and allow the verbs create, get, and proxy on the resources customresources and customresources/status.
Command: ```bash kubectl create clusterrole view --verb=create,get,proxy --resource=customresources,customresources/status ``` 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 fla...
Set the custom TLS server name to use for validation for the cluster-gamma cluster entry.
Command: ```bash kubectl config set-cluster cluster-gamma --tls-server-name=dev-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...
Create a copy of the "media-stream-pod" with a debug container and change the container images of "mailer" and "api"
Command: ```bash kubectl debug media-stream-pod -it --copy-to=debug-image-app --image=debian --set-image=mailer=mailer:latest,api=api:v2 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource an...
Change the cluster field of a context to a specified value
Command: ```bash kubectl config set contexts.app-2-context.cluster cloud-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 w...
Display only the most recent 43 lines of output in the 'mypod' pod
Command: ```bash kubectl logs --tail=43 mypod ``` 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", "def...
Set the custom TLS server name to 'web-cluster' for the 'dev-cluster' cluster entry
Command: ```bash kubectl config set-cluster dev-cluster --tls-server-name=web-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-a...
Create a service for the replicated wordpress using the replica set 'wordpress', serving on port 8081, and connecting to the containers on port 808300.
Command: ```bash kubectl expose rs wordpress --port=8081 --target-port=808300 ``` 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 service for a replicated node named "node" which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rc node --port=8082 --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 port. A...
view the details of revision 1 of the services daemonset rollout history
Command: ```bash kubectl rollout history daemonset/services --revision=1 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL t...
Create an ingress called 'external-ingress' with a rule that forwards requests for 'testing.com/bar' to the service 'svc1' with port '7000', and use the TLS secret 'my-cert'
Command: ```bash kubectl create ingress external-ingress --rule="testing.com/bar=svc1:7000,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...
Set the client-key-data field in the system user by providing the certificate data and enabling the --set-raw-bytes option.
Command: ```bash kubectl config set users.system.client-key-data cert_data_here --set-raw-bytes=true ``` 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...
Add an annotation to the pod 'web' with the key 'release-notes' and the value 'https://example.com/release-notes/v2.5.1'
Command: ```bash kubectl annotate pods web 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 can be larger t...
Retrieve previous logs of a terminated container named "quantum-quark" from the pod "log-aggregator-pod"
Command: ```bash kubectl logs -p -c quantum-quark log-aggregator-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...
Import the 'api_key' key from the config map 'db-config' into the 'monitoring-stack-deployment' deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/db-config deployment/monitoring-stack-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...
Create an ingress named "external-ingress" that directs requests to the path "/example" of the domain "website.com" to the service named "svc1" running on port 8082
Command: ```bash kubectl create ingress external-ingress --rule="website.com/example=svc1:8082,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": "", ...
Create a copy of the monitoring-pod, with a debug container and changing container images
Command: ```bash kubectl debug monitoring-pod -it --copy-to=debug-image-api --image=debian --set-image=app=app:debug,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and n...
Create a job named "report-generation-job" using the Python image. The job should execute the command "pip --version".
Command: ```bash kubectl create job report-generation-job --image=python -- pip --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": "Out...
Get output from rocket-ranger in the backend-pod
Command: ```bash kubectl attach backend-pod -c rocket-ranger ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Change the default editor to gedit, and then edit the specified service using the new editor.
Command: ```bash KUBE_EDITOR="gedit" kubectl edit svc/docker-registry ``` 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 variable...
Forward local ports 8000 and 6000 to ports 8000 and 6000 in the pod selected by the email-server-deployment deployment.
Command: ```bash kubectl port-forward deployment/email-server-deployment 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...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/db-config deployment/database-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...
Create a pod disruption budget named "messaging-pdb" that selects all pods with the "env=production" label and requires at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=env=production --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 [...
Switch to raw terminal mode and attach to the container named "cosmic-container" in the pod "email-service-pod".
Command: ```bash kubectl attach email-service-pod -c cosmic-container -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name....
Enable autoscaling for the 'proxy' deployment with a minimum of 7 pods and a maximum of 13 pods.
Command: ```bash kubectl autoscale deployment proxy --min=7 --max=13 ``` 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 t...
Forward local port 5000 to port 9090 in the analytics-pod pod.
Command: ```bash kubectl port-forward pod/analytics-pod 5000 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 auto...
import the environment variable "api-secret-key" from the secret into the deployment "search-engine-deployment"
Command: ```bash kubectl set env --from=secret/api-secret-key deployment/search-engine-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 in one or more ...
Start a busybox pod with the python image, keep it in the foreground, and prevent it from being restarted if it exits
Command: ```bash kubectl run -i -t busybox --image=python --restart=Never ``` 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: "fla...
Automatically adjust the number of pods in a replication controller named "proxy-server" based on CPU utilization, with a minimum of 1 pod and a maximum of 8 pods.
Command: ```bash kubectl autoscale rc proxy-server --max=8 --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...
set the CPU and memory resource requests and limits for all containers in the MySQL deployment
Command: ```bash kubectl set resources deployment mysql --limits=cpu=200m,memory=512Mi --requests=cpu=200m,memory=128Mi ``` 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 reques...
Auto scale the "proxy-server" deployment with a minimum of 2 pods and a maximum of 11 pods.
Command: ```bash kubectl autoscale deployment proxy-server --min=2 --max=11 ``` 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...
Output the modified deployment in YAML format without making any changes to the object on the server.
Command: ```bash kubectl set env deployment/monitoring-stack-deployment PORT=8080 -o yaml ``` 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 temp...
create a config map named app-settings from specified files
Command: ```bash kubectl create configmap app-settings --from-file=properties=/path/to/settings/file1.txt --from-file=key1=/path/to/profiles/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 creating...
Forward local port 8081 to port 9090 in the pod called "api-service-pod", and listen on both localhost and IP 10.19.21.23.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-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 cri...
Set the custom TLS server name 'testing-cluster' for the 'sun-cluster' cluster entry
Command: ```bash kubectl config set-cluster sun-cluster --tls-server-name=testing-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] [--certifica...
Scale the stateful set named 'web' to 5 replicas
Command: ```bash kubectl scale --replicas=5 statefulset/web ``` 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 is specified, it is validat...
Set the resource request and limits for all containers in the 'ruby' deployment
Command: ```bash kubectl set resources deployment ruby --limits=cpu=200m,memory=512Mi --requests=cpu=10,memory=256Mi ``` 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 requested...
Attach to a specific container in a pod, and establish a raw terminal session with it.
Command: ```bash kubectl attach api-service-pod -c rocket-ranger -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Set the custom TLS server name for app-cluster
Command: ```bash kubectl config set-cluster app-cluster --tls-server-name=cluster-beta ``` 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-...
Check if I have permission to list a specific job in a namespace
Command: ```bash kubectl auth can-i list jobs.batch/security-scan-job -n kube-public ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial ...
Listen and forward traffic from port 6379 on all addresses to port 8080 in the frontend-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 6379:8080 ``` 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...
Check if you have permission to list the "log-analysis-job" in the "logging" namespace
Command: ```bash kubectl auth can-i list jobs.batch/log-analysis-job -n logging ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL t...
Update the cluster role binding for kube-dns by setting the subject to the service account in the specified namespace.
Command: ```bash kubectl set subject clusterrolebinding admin --serviceaccount=namespace:kube-dns ``` What it does: Update the user, group, or service account in a role binding or cluster role binding. Syntax: `kubectl set subject (-f FILENAME | TYPE NAME) [--user=username] [--group=groupname] [--serviceaccount=names...
Add a taint to the node 'gpu-node-12' to indicate that it should not schedule pods without an environment value.
Command: ```bash kubectl taint nodes gpu-node-12 environment:NoSchedule ``` 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": "Output format. One o...
Create a copy of the 'proxy-service-pod' and add a debug container
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=debug-image-api --image=debian --set-image=proxy=nginx:1.21,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by ...
Start a pod named hazelcast using the centos image, and expose port 8080 within the container.
Command: ```bash kubectl run hazelcast --image=centos --port=8080 ``` 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": "--f...
Create a pod named "hazelcast" using the "mongo" image, and expose port 8089.
Command: ```bash kubectl run hazelcast --image=mongo --port=8089 ``` 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...