prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a copy of the proxy-service-pod with a debug container, and change the container images for the cache and api.
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=debug-image-1 --image=debian --set-image=cache=redis:alpine,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 and n...
Set up autoscaling for the deployment "chat-app" with a minimum of 6 pods and a maximum of 9 pods
Command: ```bash kubectl autoscale deployment chat-app --min=6 --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...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-config-dev deployment/frontend-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 defin...
Create a new config map named app-secrets, using the properties file "/path/to/profiles/file1.txt" and the key file "/path/to/configs/file2.txt" as the values for the respective keys.
Command: ```bash kubectl create configmap app-secrets --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/path/to/configs/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...
Begin streaming the logs of the "rocket-ranger" container in the "web-app-pod" pod.
Command: ```bash kubectl logs -f -c rocket-ranger web-app-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", "sh...
Create a copy of the email-service-pod with a debug container and change container images
Command: ```bash kubectl debug email-service-pod -it --copy-to=debug-image-1 --image=debian --set-image=mailer=mailer:latest,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 b...
Create a secret named email-credentials-secret with keys for each file in the specified folder.
Command: ```bash kubectl create secret generic email-credentials-secret --from-file=path/to/parameters ``` 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 b...
Auto scale the replication controller "proxy-server" with a target CPU utilization of 81% and a maximum of 6 pods
Command: ```bash kubectl autoscale rc proxy-server --max=6 --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 that...
Run the 'jenkins-plugin-cli' command in the vpn-service-pod container and get the output
Command: ```bash kubectl exec vpn-service-pod -- jenkins-plugin-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, use th...
Set the cluster field in the dev-context context to staging-cluster
Command: ```bash kubectl config set contexts.dev-context.cluster staging-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...
Create a service for the 'python' deployment, which serves on port 6379 and connects to the containers on port 8000
Command: ```bash kubectl expose deployment python --port=6379 --target-port=8000 ``` 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...
Rename the context 'staging-context' to 'team-alpha-context' in your kubeconfig file
Command: ```bash kubectl config rename-context staging-context team-alpha-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 wil...
Scale the deployment named app-v2-replicaset to 5 replicas if its current size is 3
Command: ```bash kubectl scale --current-replicas=3 --replicas=5 deployment/app-v2-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...
Create a role named "default_role" with the verb set to "delete" and the resource set to "pods", with additional resource names specified as "staging-app-server"
Command: ```bash kubectl create role default_role --verb=delete --resource=pods --resource-name=staging-app-server --resource-name=staging-app-server ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--...
Forward local port 5432 to port 8080 in the pod "backend-pod"
Command: ```bash kubectl port-forward pod/backend-pod 5432 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 automa...
Add a taint with the key 'app' and value 'testing-node-11:PreferNoSchedule' on nodes that have the label 'cluster=my-cluster'.
Command: ```bash kubectl taint node -l cluster=my-cluster app=testing-node-11: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...
Forward local port 8080 to port 3000 in the pod named proxy-server-pod
Command: ```bash kubectl port-forward pod/proxy-server-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 a...
Forward traffic from port 8088 on all addresses to port 8081 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-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 w...
Forward local port 8088 to port 8081 in the e-commerce-pod
Command: ```bash kubectl port-forward pod/e-commerce-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 aut...
Change the service account of the deployment "search-engine-deployment" to "argocd"
Command: ```bash kubectl set serviceaccount deployment search-engine-deployment argocd ``` 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: `kubec...
Create an ingress named 'ingress1' with multiple hosts and set the pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="testing.com/path*=svc:8083" \ --rule="input.com/admin*=svc2:http" ``` 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...
Connect to the 'log-aggregator-pod' pod, specifically to the 'nano-bot' container, and switch to a raw terminal mode, allowing you to interact with the 'bash' shell
Command: ```bash kubectl attach log-aggregator-pod -c nano-bot -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 omi...
Run the command 'apk add curl' inside the 'rocket-ranger' container of the 'vpn-service-pod' pod and display the output.
Command: ```bash kubectl exec vpn-service-pod -c rocket-ranger -- apk add curl ``` 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 omit...
Create a new config map named monitoring-config with specified keys and file paths
Command: ```bash kubectl create configmap monitoring-config --from-file=settings=/path/to/settings/file1.txt --from-file=key2=/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...
Set the CPU limits of the Elasticsearch container in a deployment to 3 and the memory limits to 1Gi.
Command: ```bash kubectl set resources deployment elasticsearch -c=nginx --limits=cpu=3,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, but may burst up...
import the 'CONFIG_FILE_PATH' key from the 'kube-system-config' ConfigMap and set it as an environment variable in the 'order-processing-deployment' deployment
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/kube-system-config 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 va...
Add a taint with key 'app' on nodes with the label 'service=auth'
Command: ```bash kubectl taint node -l service=auth app=web-node-8: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": "Output ...
Run the 'jenkins-plugin-cli' command in the 'time-machine' container of the 'web-app-pod' pod and display the output.
Command: ```bash kubectl exec web-app-pod -c time-machine -- jenkins-plugin-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 omi...
Set a custom TLS server name for the sun-cluster cluster entry
Command: ```bash kubectl config set-cluster sun-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-...
Create an ingress named "ingdefault" with a default backend in the default class
Command: ```bash kubectl create ingress ingdefault --class=default \ --default-backend=defaultsvc:http \ --rule="site.com/*=svc:9090,tls=secret1" ``` 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": "--o...
Set the CPU and memory limits for the nginx container in a deployment
Command: ```bash kubectl set resources deployment nginx -c=nginx --limits=cpu=100m,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, but may burst up to i...
Auto scale the deployment "database" with the number of pods between 5 and 15.
Command: ```bash kubectl autoscale deployment database --min=5 --max=15 ``` 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 use...
Import the 'api_key' key from the 'api-config' config map to the 'gateway-deployment' deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/api-config deployment/gateway-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 ...
Add a taint on nodes with a specific label
Command: ```bash kubectl taint node -l app=web-app cpu-type=worker-node-3: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": "...
Expose the node deployment as a service, serving on port 5432 and connecting to the containers on port 700000.
Command: ```bash kubectl expose deployment node --port=5432 --target-port=700000 ``` 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...
Listen on local port 8888 and forward data to/from port 5432 in the log-aggregator-pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8888 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 will be selected...
create a job named deployment-rollout-job using the ethereum/client-go image and execute the command "geth version"
Command: ```bash kubectl create job deployment-rollout-job --image=ethereum/client-go -- geth 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": "", "...
Set the service account of the deployment 'scheduler-app-deployment' to 'tekton'
Command: ```bash kubectl set serviceaccount deployment scheduler-app-deployment tekton ``` 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: `kubec...
Set up the 'prod-cluster' cluster with embedded certificate authority data from the specified file "~/.kube/edge-cluster/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster prod-cluster --embed-certs --certificate-authority=~/.kube/edge-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...
Create a new ExternalName service named external-caching-service with an external name of practice-online.site
Command: ```bash kubectl create service externalname external-caching-service --external-name practice-online.site ``` 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...
Forward port 5432 from your local machine to port 8088 in the pod named security-service-pod
Command: ```bash kubectl port-forward pod/security-service-pod 5432: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...
List all allowed actions in the "development" namespace.
Command: ```bash kubectl auth can-i --list --namespace=development ``` 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 that starts wi...
Output the modified payment-processor-deployment deployment with the updated DB_HOST environment variable set to localhost in YAML format, without making any changes to the deployment on the server.
Command: ```bash kubectl set env deployment/payment-processor-deployment DB_HOST=localhost -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...
Auto scale the deployment named "security" with the minimum number of pods set to 5 and the maximum number of pods set to 10.
Command: ```bash kubectl autoscale deployment security --min=5 --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 use...
Edit the last-applied-configuration annotations for a deployment named "jenkins" in YAML format
Command: ```bash kubectl apply edit-last-applied deployment/jenkins ``` What it does: Edit the latest last-applied-configuration annotations of resources from the default editor. The edit-last-applied command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the edi...
Forward traffic from port 5432 on localhost and IP 10.19.21.23 to port 8888 in the pod named "web-app-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-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 criteri...
Create a copy of 'database-pod' and change all container images to 'redis'
Command: ```bash kubectl debug database-pod --copy-to=debug-image-memcached --set-image=*=redis ``` 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 n...
Create a new pod named 'nginx' using the 'jenkins' image, and specify the pod specification by providing a partial set of values parsed from the JSON override object with apiVersion "v2.1.0".
Command: ```bash kubectl run nginx --image=jenkins --overrides='{ "apiVersion": "v2.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] -- [COMMA...
Create a config map named kube-system-config with key1=config1 and key2=config2
Command: ```bash kubectl create configmap kube-system-config --from-literal=conf=config1 --from-literal=data=config2 ``` 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 config map based on a file, the...
Update the cluster field in the context 'app-2-context' to 'on-prem-cluster'.
Command: ```bash kubectl config set contexts.app-2-context.cluster on-prem-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 service for a replicated Ubuntu using replica set, which serves on port 8084 and connects to the containers on port 808800
Command: ```bash kubectl expose rs ubuntu --port=8084 --target-port=808800 ``` 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....
Create a service for a replicated Centos using Replica Set, serving on port 9091 and connecting to the containers on port 800000.
Command: ```bash kubectl expose rs centos --port=9091 --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 port....
Check if the current user has permission to list the job named "data-synchronization-job" in the "kube-public" namespace
Command: ```bash kubectl auth can-i list jobs.batch/data-synchronization-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 p...
Import the specific API_KEY key from the app-config-prod config map to the payment-processor-deployment deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-config-prod deployment/payment-processor-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 an ingress called 'www-ingress' with a rule that directs requests to 'website.com/bar' to the service 'svc1' on port 9000
Command: ```bash kubectl create ingress www-ingress --rule="website.com/bar=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": "", "usage": ...
Execute the 'mysql' command inside the first pod of the 'web-app-deployment' deployment and retrieve the output.
Command: ```bash kubectl exec deploy/web-app-deployment -- mysql ``` 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 k...
Create a new config map named global-config using specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap global-config --from-file=conf=/path/to/settings/file1.txt --from-file=data=/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 config...
Create an ingress called 'external-ingress' to route requests for website.com/example to svc1 on port 8443, with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress external-ingress --rule="website.com/example=svc1:8443,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": "", ...
Display the replication controller 'web', the service 'email-service-rc', and the pod 'proxy-service-pod'
Command: ```bash kubectl get rc/web service/email-service-rc pods/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 na...
Delete a specific context
Command: ```bash kubectl config delete-context user-b-context ``` What it does: Delete the specified context from the kubeconfig. Syntax: `kubectl config delete-context NAME`
Set the cluster for a specific context
Command: ```bash kubectl config set contexts.client-1-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 y...
Partially update a node using a strategic merge patch
Command: ```bash kubectl patch -f cni.conf -p '{"spec":{"unschedulable":true}}' ``` 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...
Get the output of the command 'gem --version' from the first pod of the deployment 'search-engine-deployment'.
Command: ```bash kubectl exec deploy/search-engine-deployment -- gem --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 omit...
Forward local ports 5432 and 6000 to ports 8080 and 6000, respectively, in a pod selected by the deployment "analytics-platform-deployment".
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 5432 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 po...
Add a taint with key 'workload' on nodes having label namespace=mynamespace, with the value 'PreferNoSchedule' for the node 'web-node-8'.
Command: ```bash kubectl taint node -l namespace=mynamespace workload=web-node-8: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 job with a command to execute
Command: ```bash kubectl create job monitoring-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 format. On...
create a new ExternalName service named external-cloud-storage-service with the external name set to mockup-cloud.cloud
Command: ```bash kubectl create service externalname external-cloud-storage-service --external-name mockup-cloud.cloud ``` 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 refer...
Create a pod disruption budget named 'elastic-search-pdb' that will select all pods with the 'tier=frontend' label and require at least four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget elastic-search-pdb --selector=tier=frontend --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...
View the previous terminated logs of the "astro-container" container from the pod "cdn-service-pod"
Command: ```bash kubectl logs -p -c astro-container 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...
create a job named "log-collection" using the "node" image and run the "node" command
Command: ```bash kubectl create job log-collection --image=node -- node ``` 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...
Check if you have permission to list the job named "queue-processing-job" in the namespace "kube-ingress"
Command: ```bash kubectl auth can-i list jobs.batch/queue-processing-job -n kube-ingress ``` 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 part...
Remove all the taints with key 'zone' from the 'kube-master-9' node.
Command: ```bash kubectl taint nodes kube-master-9 zone- ``` 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|yaml|na...
Forward local port 6379 to port 8000 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 6379: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 a...
Listen on port 3000 locally and forward traffic to port 8080 in the 'analytics-pod' pod
Command: ```bash kubectl port-forward pod/analytics-pod 3000: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 auto...
Execute the command `mysqld` in the first container of the first pod of the `order-processing-deployment`.
Command: ```bash kubectl exec deploy/order-processing-deployment -- 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,...
Set the service account of the deployment "payment-processor-deployment" to "kube-dns"
Command: ```bash kubectl set serviceaccount deployment payment-processor-deployment kube-dns ``` 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: ...
Set the last-applied-configuration of the resource to match the contents of the options.yaml file and create the annotation if it does not already exist.
Command: ```bash kubectl apply set-last-applied -f options.yaml --create-annotation=true ``` What it does: Set the latest last-applied-configuration annotations by setting it to match the contents of a file. This results in the last-applied-configuration being updated as though 'kubectl apply -f ' was run, without upd...
Listen on port 8081 locally, forwarding data to/from port 9090 in a pod selected by the deployment named authentication-service-deployment.
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 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, ...
Forward local port 9090 to port 8888 in the cdn-service-pod pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 9090: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 will be selected au...
Set the resource request and limits for all containers in the python deployment
Command: ```bash kubectl set resources deployment python --limits=cpu=200m,memory=512Mi --requests=cpu=5,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 requested...
Create a copy of cdn-service-pod with all container images changed to redis
Command: ```bash kubectl debug cdn-service-pod --copy-to=debug-image-api --set-image=*=redis ``` 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 r...
Update a specific field of a node by applying a strategic merge patch using a YAML file
Command: ```bash kubectl patch node worker-node-3 -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]` Helpfu...
Switch to the raw terminal mode for the 'proxy-service-pod' pod, specifically for the 'quantum-quark' container
Command: ```bash kubectl attach proxy-service-pod -c quantum-quark -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...
Set up the e2e cluster entry with embedded certificate authority data
Command: ```bash kubectl config set-cluster e2e --embed-certs --certificate-authority=~/.kube/e2e/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-cluster NAME [--s...
Partially update the node node-1 by setting the `unschedulable` field to `true` using a strategic merge patch in JSON format.
Command: ```bash kubectl patch node node-1 -p '{"spec":{"unschedulable":true}}' ``` 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...
Get the output of the 'jenkins --version' command from the 'analytics-pod' pod.
Command: ```bash kubectl exec analytics-pod -- jenkins --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, use the k...
Expose the replica set "wordpress" as a service, mapping port 8000 on the service to port 8080 on the container
Command: ```bash kubectl expose rs wordpress --port=8000 --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 po...
Create an ingress called 'private-service-ingress' that directs requests to site.com/bar to the service 'svc1' running on port 9092
Command: ```bash kubectl create ingress private-service-ingress --rule="site.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": "", ...
Create a copy of the payment-gateway-pod named debug-image-1, and change all container images to python.
Command: ```bash kubectl debug payment-gateway-pod --copy-to=debug-image-1 --set-image=*=python ``` 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 n...
Listen on port 9090 on all addresses and forward the traffic to port 6379 in the log-aggregator-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-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 po...
Create a copy of the monitoring-pod and change all container images to mongo. Name the new debugger pod as my-debugger.
Command: ```bash kubectl debug monitoring-pod --copy-to=my-debugger --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...
Retrieve the logs from the first container of the job named image-processing-job.
Command: ```bash kubectl logs job/image-processing-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": "...
update the pod identified by the type and name in the "pod.json" file and add the annotation "monitoring-tool=Prometheus"
Command: ```bash kubectl annotate -f pod.json monitoring-tool=Prometheus ``` 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 arbi...
Add a taint with key 'app' and no value to the 'backup-node-14' node
Command: ```bash kubectl taint nodes backup-node-14 app: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: js...
Start a python pod and expose port 8443
Command: ```bash kubectl run hazelcast --image=python --port=8443 ``` 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...
Forward local port 8088 to port 9090 in the selected pod of the deployment
Command: ```bash kubectl port-forward deployment/notification-handler-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 ...
Create a new pod named "hazelcast" using the "node" image and expose port 8181
Command: ```bash kubectl run hazelcast --image=node --port=8181 ``` 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": "--fil...
Forward traffic from local port 8888 to port 5432 in the pod "security-service-pod"
Command: ```bash kubectl port-forward pod/security-service-pod 8888: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 will be select...
List the specified resources by their type and names.
Command: ```bash kubectl get rc/web service/log-aggregator-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 namespa...
Get the output from running the 'dotnet --list-sdks' command in the rocket-ranger container of the analytics-pod pod.
Command: ```bash kubectl exec analytics-pod -c rocket-ranger -- 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. If ...