prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Add a 'PreferNoSchedule' taint with the key 'workload' on all nodes that have the label 'owner' set to 'john-doe'.
Command: ```bash kubectl taint node -l owner=john-doe workload=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": "...
Embed the certificate authority data for the web-cluster cluster entry and set the certificate authority path to "~/.kube/cluster-alpha/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster web-cluster --embed-certs --certificate-authority=~/.kube/cluster-alpha/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...
Copy a file named "foo" from the "/tmp" directory of a remote pod to the "/tmp" directory on your local machine.
Command: ```bash kubectl exec -n kube-dns backend-pod-13 -- tar cf - /tmp/foo | tar xf - -C :/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...
Import environment variables from a ConfigMap with a specific prefix for a deployment.
Command: ```bash kubectl set env --from=configmap/api-config --prefix=MYSQL_ 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 ...
List the replication controller named "web", the service replication controller named "api-service-rc", and the pod named "email-service-pod"
Command: ```bash kubectl get rc/web service/api-service-rc pods/email-service-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 name...
create a job named security-scan-job using the image confluentinc/cp-kafka and execute the command "kafka-topics --list"
Command: ```bash kubectl create job security-scan-job --image=confluentinc/cp-kafka -- kafka-topics --list ``` 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": ...
Forward local port 8888 to port 8088 in the pod named security-service-pod
Command: ```bash kubectl port-forward pod/security-service-pod 8888:8088 ``` 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 select...
Apply a taint to nodes in the us-east-1 zone labeling them with the key 'cpu-type' and the value 'gpu-node-12' and mark them as unschedulable using the PreferNoSchedule effect.
Command: ```bash kubectl taint node -l zone=us-east-1 cpu-type=gpu-node-12: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": ...
Copy the ~/.config/kube local file to the /tmp/bar_dir directory inside the 'monitoring-agent-pod-6' pod in the 'openfaas' namespace
Command: ```bash kubectl cp ~/.config/kube openfaas/monitoring-agent-pod-6:/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, ...
Retrieve the password for the user 'app-cluster' in the kubectl configuration.
Command: ```bash kubectl config view -o jsonpath='{.users[?(@.name == "app-cluster")].user.password}' ``` What it does: Display merged kubeconfig settings or a specified kubeconfig file. You can use --output jsonpath={...} to extract specific values using a jsonpath expression. Syntax: `kubectl config view` Helpful ...
Get the output of the 'kafka-topics --list' command from the first pod of the database-deployment deployment.
Command: ```bash kubectl exec deploy/database-deployment -- kafka-topics --list ``` 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 omi...
Get output from running a command inside a container in a pod.
Command: ```bash kubectl exec analytics-pod -c mycontainer -- sleep 3600 ``` 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...
Import the 'config_file_path' key from the 'app-config-prod' ConfigMap into the 'order-processing-deployment' deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-config-prod deployment/order-processing-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 varia...
Import the 'log_level' key from the 'ui-config' config map to the 'cache-cluster-deployment' deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/ui-config deployment/cache-cluster-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 ...
Update the 'gateway' pod by adding or modifying the 'expiration-date' annotation to the value '2024-12-31'
Command: ```bash kubectl annotate pods gateway expiration-date='2024-12-31' ``` 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...
Create a new secret named aws-credentials-secret from an env file
Command: ```bash kubectl create secret generic aws-credentials-secret --from-env-file=path/to/options.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 th...
Create a new config map named app-settings by specifying keys and their corresponding file paths.
Command: ```bash kubectl create configmap app-settings --from-file=settings=/path/to/settings/file1.txt --from-file=key2=/path/to/preferences/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 creatin...
Create a new config map named namespace-config using specified key-values instead of file basenames on disk
Command: ```bash kubectl create configmap namespace-config --from-file=properties=/path/to/options/file1.txt --from-file=key1=/path/to/parameters/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 an ingress named 'myapp-ingress' that routes requests from foo.com/bar to svc1:9092 using a TLS secret named "my-cert"
Command: ```bash kubectl create ingress myapp-ingress --rule="foo.com/bar=svc1:9092,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": "O...
Import the specific key 'config_file_path' from the 'app-config' config map into the 'cache-cluster-deployment' deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-config deployment/cache-cluster-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 defi...
Create a new ClusterIP service named auth-service-clusterip that forwards traffic from port 5000 to port 9091.
Command: ```bash kubectl create service clusterip auth-service-clusterip --tcp=5000:9091 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "...
Forward port 8000 from local host and IP 10.19.21.23 to port 8000 in the pod "mypod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 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 p...
Create an ingress called 'internal-ingress' with a rule that directs requests to 'website.com/example' to 'svc1:8888'
Command: ```bash kubectl create ingress internal-ingress --rule="website.com/example=svc1:8888,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": "", ...
List the non-namespaced resources that are supported by the API server.
Command: ```bash kubectl api-resources --versionspaced=false ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Show the metrics for the 'node-2' node
Command: ```bash kubectl top node node-2 ``` What it does: Display resource (CPU/memory) usage of nodes. The top-node command allows you to see the resource consumption of nodes. Syntax: `kubectl top node [NAME | -l label]` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label ...
Create a new secret named api-key-secret and include keys for each file in the bar folder.
Command: ```bash kubectl create secret generic api-key-secret --from-file=path/to/data ``` 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 of the f...
List the pod specified in the "setup.yaml" file with YAML output format.
Command: ```bash kubectl get -f setup.yaml -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 namespaced you will only see result...
Create a job named 'audit-job' using the image 'jenkins' and run the command 'jenkins-plugin-cli'
Command: ```bash kubectl create job audit-job --image=jenkins -- jenkins-plugin-cli ``` 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 fo...
Execute the 'yum install -y wget' command in the payment-gateway-pod and display the output.
Command: ```bash kubectl exec payment-gateway-pod -- yum install -y wget ``` 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...
List the replication controller named 'web', the service named 'frontend-rc', and the pod named 'backend-pod'
Command: ```bash kubectl get rc/web service/frontend-rc pods/backend-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 yo...
Forward traffic from port 8888 on localhost and IP 10.19.21.23 to port 8080 in the pod named 'proxy-server-pod'
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 8888: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 cr...
Remove taints with key 'environment' from node 'gpu-node-12'
Command: ```bash kubectl taint nodes gpu-node-12 environment- ``` 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 of: json|ya...
Set the cluster field in a specific context to a specific cluster
Command: ```bash kubectl config set contexts.cloud-context.cluster cluster-gamma ``` 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...
Retrieve the logs from all containers within the pod "cdn-service-pod"
Command: ```bash kubectl logs cdn-service-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": "--container...
Create a pod disruption budget named worker-pdb that will select all pods with the release=1.0.0 label and require a minimum of four of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget worker-pdb --selector=release=1.0.0 --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 [--dr...
Create an ingress named 'myapp-ingress' that routes requests from 'testing.com/module' to 'svc1:3000' with a TLS secret named 'my-cert'
Command: ```bash kubectl create ingress myapp-ingress --rule="testing.com/module=svc1:3000,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...
List the desired resources by their type and names
Command: ```bash kubectl get rc/web service/proxy-server-rc pods/gateway-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 namespace...
Set the CPU limits for the 'redis' deployment's 'nginx' container to 5 units and the memory limit to 256 megabytes.
Command: ```bash kubectl set resources deployment redis -c=nginx --limits=cpu=5,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, but may burst up to it...
Create an ingress resource named 'app2-ingress' that maps requests for 'foo.com/example' to the service 'svc1' on port 3001 and uses the TLS secret 'my-cert' for secure communication.
Command: ```bash kubectl create ingress app2-ingress --rule="foo.com/example=svc1:3001,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":...
List deployments in the "custom-version" version of the "custom-deployments" API group, with JSON output format
Command: ```bash kubectl get deployments.custom-version.custom-deployments -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 nam...
Create a new config map named app-settings using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-settings --from-file=settings=/path/to/preferences/file1.txt --from-file=key2=/path/to/properties/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...
Listen on a random port locally, forwarding to the 8000 port in the 'analytics-pod' pod
Command: ```bash kubectl port-forward pod/analytics-pod :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 automati...
update the environment variable of deployment 'log-aggregator-deployment' with a new value
Command: ```bash kubectl set env deployment/log-aggregator-deployment SMTP_PASSWORD=your-password ``` 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 ...
Run the command 'mongo --version' in the 'cosmic-container' from the pod 'media-stream-pod' and display the output.
Command: ```bash kubectl exec media-stream-pod -c cosmic-container -- mongo --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. ...
Listen on port 8888 on your local machine and forward the traffic to port 8081 in the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 8888: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 au...
Forward traffic from port 8088 on all addresses to port 5432 in the analytics-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8088: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 criteria, a pod wil...
Set the CPU and memory limits to 200m and 512Mi respectively, and set the CPU and memory requests to 50m and 2Gi respectively for all containers in the nginx deployment.
Command: ```bash kubectl set resources deployment nginx --limits=cpu=200m,memory=512Mi --requests=cpu=50m,memory=2Gi ``` 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...
set the resource request and limits for all containers in the php deployment
Command: ```bash kubectl set resources deployment php --limits=cpu=200m,memory=512Mi --requests=cpu=200m,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 requested,...
Create a copy of the gateway-pod and open a debug session with the my-debugger pod, specifically targeting the warp-drive container.
Command: ```bash kubectl debug gateway-pod -it --copy-to=my-debugger --container=warp-drive -- 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 if...
Create a copy of the log-aggregator-pod with a different command for the cosmic-container
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-1 --container=cosmic-container -- 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 use...
Create a new pod named "nginx" using the image "mcr.microsoft.com/dotnet/core/runtime", but override the pod specification with a partial set of values parsed from JSON
Command: ```bash kubectl run nginx --image=mcr.microsoft.com/dotnet/core/runtime --overrides='{ "apiVersion": "v1.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=inli...
Create a cron job to send email notifications using the specified image and schedule
Command: ```bash kubectl create cronjob email-notifications --image=confluentinc/cp-kafka --schedule="*/1 * * * *" -- kafka-console-producer --broker-list localhost:9092 --topic test ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?...
Forward local traffic on port 8000 to a pod's port 5000
Command: ```bash kubectl port-forward pod/api-service-pod 8000 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 au...
Begin streaming the logs of the "ruby" container in the "proxy-server-pod" pod.
Command: ```bash kubectl logs -f -c ruby 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"...
Use the 'vi' editor to edit the 'scheduler-service' service
Command: ```bash KUBE_EDITOR="vi" kubectl edit svc/scheduler-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 variables...
Execute the 'ash' command in the 'quantum-quark' container of the 'vpn-service-pod' pod
Command: ```bash kubectl exec vpn-service-pod -c quantum-quark -- ash ``` 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 ...
Create a custom role named "custom_role" with specific permissions for a specific API Group.
Command: ```bash kubectl create role custom_role --verb=create,get,proxy --resource=clusterrolebindings.rbac.authorization.k8s.io ``` 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...
Create a copy of the monitoring-pod with different container images by using the kubectl debug command
Command: ```bash kubectl debug monitoring-pod --copy-to=my-debugger --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 name. P...
Create a new secret named 'password-secret' using the parameters specified in the 'path/to/parameters.env' env file.
Command: ```bash kubectl create secret generic password-secret --from-env-file=path/to/parameters.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 ba...
Get the output of running the 'irb' command in the 'stardust-shuttle' container in the 'vpn-service-pod' pod.
Command: ```bash kubectl exec vpn-service-pod -c stardust-shuttle -- irb ``` 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...
Create a service for the replicated wordpress using replica set, serving on port 9090 and connecting to the containers on port 8000
Command: ```bash kubectl expose rs wordpress --port=9090 --target-port=800000 ``` 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 new config map named 'app-name-config' using the 'settings' key from the '/path/to/configs/file1.txt' file and the 'key2' key from the '/path/to/options/file2.txt' file.
Command: ```bash kubectl create configmap app-name-config --from-file=settings=/path/to/configs/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 creating ...
Remove a taint from a node
Command: ```bash kubectl taint nodes dev-node-4 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 of: ...
Create a new generic secret named my-secret, with ssh-privatekey and ssh-publickey as keys, using the files located at path/to/id_rsa and path/to/id_rsa.pub respectively.
Command: ```bash kubectl create secret generic my-secret --from-file=ssh-privatekey=path/to/id_rsa --from-file=ssh-publickey=path/to/id_rsa.pub ``` 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...
Set the custom TLS server name to "data-cluster" for the "edge-cluster" cluster entry
Command: ```bash kubectl config set-cluster edge-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 DEBUG_MODE key from the config map 'namespace-config' and set it as an environment variable in the 'database-deployment' deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/namespace-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 definitio...
Retrieve information about a specific pod in YAML format
Command: ```bash kubectl get -o yaml pod proxy-service-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 you will only se...
Set resource request and limits for all containers in Jenkins deployment
Command: ```bash kubectl set resources deployment jenkins --limits=cpu=200m,memory=512Mi --requests=cpu=10,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...
Remove all the taints with key 'datacenter' from the 'worker-node-3' node
Command: ```bash kubectl taint nodes worker-node-3 datacenter- ``` 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 of: json|y...
Create a new config map named monitoring-config with the specified keys and file paths
Command: ```bash kubectl create configmap monitoring-config --from-file=properties=/path/to/data/file1.txt --from-file=key1=/path/to/configurations/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 c...
import the 'MAX_CONNECTIONS' key from the 'app-secrets' config map into the 'search-engine-deployment' deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-secrets 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 defi...
Create a new secret named 'password-secret' with keys for each file in the 'path/to/options' folder
Command: ```bash kubectl create secret generic password-secret --from-file=path/to/options ``` 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 of t...
Create the secret 'jwt-secret' with keys for each file in the 'path/to/configurations' folder.
Command: ```bash kubectl create secret generic jwt-secret --from-file=path/to/configurations ``` 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 of...
Copy the local file "/tmp/foo_dir" to the remote pod named "auth-service-pod-11" in the "ingress-nginx" namespace at "/etc/kubernetes" directory.
Command: ```bash kubectl cp /tmp/foo_dir ingress-nginx/auth-service-pod-11:/etc/kubernetes ``` 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 omitte...
Execute the 'redis-cli' command in the 'time-machine' container of the 'frontend-pod' pod and display the output
Command: ```bash kubectl exec frontend-pod -c time-machine -- redis-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. If omitted, us...
update the environment variable 'SMTP_PASSWORD' for the deployment 'order-processing-deployment'
Command: ```bash kubectl set env deployment/order-processing-deployment SMTP_PASSWORD=your-password ``` 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 mor...
create a job named cleanup using the golang image with the command "go"
Command: ```bash kubectl create job cleanup --image=golang -- go ``` 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: json|...
Delete the pods and services named "cdn" and "media-stream"
Command: ```bash kubectl delete pod,service cdn media-stream ``` 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...
Import the REDIS_HOST key from the ui-config config map and set it as an environment variable in the proxy-service-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/ui-config deployment/proxy-service-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 called 'external-ingress' that routes requests from site.com/example to svc1:3000, using the tls secret "my-cert"
Command: ```bash kubectl create ingress external-ingress --rule="site.com/example=svc1:3000,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": "", "us...
Retrieve the details of a pod specified in the "options.yaml" file, using the json output format.
Command: ```bash kubectl get -f options.yaml -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 will only see resu...
Embed the certificate authority data for the cluster-alpha cluster entry using the command: 'kubectl config set-cluster cluster-alpha --embed-certs --certificate-authority=<path_to_cert_file>' where <path_to_cert_file> is the file path to the Kubernetes certificate authority file.
Command: ```bash kubectl config set-cluster cluster-alpha --embed-certs --certificate-authority=~/.kube/dev-cluster/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...
Update the 'env' annotation of the 'media-stream' pod to the value 'staging'.
Command: ```bash kubectl annotate pods media-stream env=staging ``` 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 str...
Add a taint with key 'zone' and value 'kube-master-9:PreferNoSchedule' on all nodes with the label 'team=devops'
Command: ```bash kubectl taint node -l team=devops zone=kube-master-9: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 a port forwarding between your local machine's port 9090 and the pod backend-pod's port 9090.
Command: ```bash kubectl port-forward pod/backend-pod 9090 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 automa...
Retrieve the snapshot logs from the container "mypod-1" in the deployment "database-deployment-1"
Command: ```bash kubectl logs deployment/database-deployment -c mypod-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 flags: "flag": "--conta...
Rename a context in the kubeconfig file
Command: ```bash kubectl config rename-context cloud-context edge-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will also b...
Taint nodes with label 'environment=production' for 'hardware=db-node-7' with 'PreferNoSchedule'
Command: ```bash kubectl taint node -l environment=production hardware=db-node-7: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...
Create a new LoadBalancer service named cdn-service-lb that listens on port 5000 and forwards traffic to port 5001.
Command: ```bash kubectl create service loadbalancer cdn-service-lb --tcp=5000:5001 ``` 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", "def...
Add a taint to the 'web-node-8' node with the key 'dedicated' and no value
Command: ```bash kubectl taint nodes web-node-8 dedicated: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 of: ...
Get detailed information about a specific node in the cluster.
Command: ```bash kubectl describe nodes analytics-node-9.analytics-cluster.local ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all ob...
Update the 'proxy' pod with the annotation 'deployment-script' and the value 'https://example.com/deploy.sh'.
Command: ```bash kubectl annotate pods proxy deployment-script='https://example.com/deploy.sh' ``` 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 l...
Forward local port 5000 to port 6379 in the 'cdn-service-pod' pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 5000 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 au...
Run the 'go' command inside the first container of the 'load-balancer-deployment' deployment.
Command: ```bash kubectl exec deploy/load-balancer-deployment -- go ``` 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...
Forward local traffic on port 8088 to the pod's port 8081 for the pod named 'cdn-service-pod'
Command: ```bash kubectl port-forward pod/cdn-service-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 au...
Add a taint with the key 'cpu-type' on nodes having the label customer=acme-corp
Command: ```bash kubectl taint node -l customer=acme-corp cpu-type=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": "...
Update a specific field of a node using a strategic merge patch.
Command: ```bash kubectl patch node db-node-7 -p $'spec:\n someField: newValue' ``` 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 FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful fl...
Forward local traffic on port 8080 to port 3000 in the 'analytics-pod'.
Command: ```bash kubectl port-forward pod/analytics-pod 8080 3000 ``` 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...
create a LoadBalancer service named 'cdn-service-lb' that forwards traffic from port 8000 to port 9000
Command: ```bash kubectl create service loadbalancer cdn-service-lb --tcp=8000:9000 ``` 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", "def...
Listen on ports 8080 and 6000 on your local machine, and forward data to/from ports 8080 and 6000 in the 'frontend-pod' pod.
Command: ```bash kubectl port-forward pod/frontend-pod 8080 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 be selected autom...