prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Return the logs from the proxy-service-deployment-1 container of the cdn-service-pod deployment
Command: ```bash kubectl logs deployment/proxy-service-deployment -c cdn-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "...
Import the DEBUG_MODE 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=DEBUG_MODE --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...
Check if you have permissions to list the job named "data-synchronization-job" in the "kube-ingress" namespace
Command: ```bash kubectl auth can-i list jobs.batch/data-synchronization-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 ...
Forward port 8080 on all addresses to port 8888 in the security-service-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 8080: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 ...
Create a pod named nginx with the alpine image, but customize the pod specification by providing a partial set of values in JSON format.
Command: ```bash kubectl run nginx --image=alpine --overrides='{ "apiVersion": "alpha-2.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] -- [COM...
Forward local port 8080 to port 3000 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-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...
Import the 'MAX_CONNECTIONS' 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=MAX_CONNECTIONS --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 d...
Create a pod disruption budget named 'elastic-search-pdb' that will select all pods with the 'env=production' label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget elastic-search-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-availabl...
Display only the most recent 3 lines of output in the e-commerce-pod pod
Command: ```bash kubectl logs --tail=3 e-commerce-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": "-...
Copy the ~/.config/kube file to the /tmp/bar_dir directory in the admin-dashboard-pod-16 pod in the kube-node-lease namespace.
Command: ```bash kubectl cp ~/.config/kube kube-node-lease/admin-dashboard-pod-16:/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 om...
Return the snapshot of previous terminated logs from the 'mycontainer' container in the 'e-commerce-pod' pod.
Command: ```bash kubectl logs -p -c mycontainer e-commerce-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "s...
Copy the file "/tmp/foo" from the remote pod "metallb-system/ingress-controller-pod-8" to the local directory "/etc/kubernetes".
Command: ```bash kubectl cp metallb-system/ingress-controller-pod-8::/tmp/foo /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 omi...
Set the custom TLS server name to "e2e" for validation for the cluster entry named "galaxy-cluster"
Command: ```bash kubectl config set-cluster galaxy-cluster --tls-server-name=e2e ``` 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-author...
Create a cron job named `weekly-summary` with the image `ubuntu`, running the command `docker run ubuntu echo "Hello"`, and a schedule of running every minute
Command: ```bash kubectl create cronjob weekly-summary --image=ubuntu --schedule="*/1 * * * *" -- docker run ubuntu echo "Hello ``` 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": "--ou...
Output the modified cache-cluster-deployment deployment in YAML format with the DEBUG environment variable set to true, without altering the object on the server
Command: ```bash kubectl set env deployment/cache-cluster-deployment DEBUG=true -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 templa...
Add a taint to the 'gpu-node-12' node with the key 'hardware' and no value, so that no new pods are scheduled on this node.
Command: ```bash kubectl taint nodes gpu-node-12 hardware: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: ...
Apply a strategic merge patch to update the specified node with the "containerd-config.toml" configuration file, setting the "unschedulable" field to true.
Command: ```bash kubectl patch -f containerd-config.toml -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...
Set the exec auth plugin environment variables for the "app-service" entry
Command: ```bash kubectl config set-credentials app-service --exec-env=key1=val1 --exec-env=key2=val2 ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=keyfile B...
Forward local port 5000 to port 8080 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-pod 5000: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 au...
Import specific keys from a config map to an environment variable in a deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/log-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 definition...
Delete the pods and services with the names "gateway" and "gateway"
Command: ```bash kubectl delete pod,service gateway gateway ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector....
Create a single ingress called 'service-ingress' that directs requests to testing.com/input to svc1:8082 with a tls secret "my-cert"
Command: ```bash kubectl create ingress service-ingress --rule="testing.com/input=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": "", "us...
Add a taint with key 'zone' on nodes having label 'instance=app-instance-1' and value 'prod-node-5' with the effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l instance=app-instance-1 zone=prod-node-5: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": "", "usa...
Create a new config map named "app-name-config" with the specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap app-name-config --from-file=conf=/path/to/settings/file1.txt --from-file=data=/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 a c...
Copy the directory /var/run/secrets/kubernetes.io/serviceaccount/ from the remote pod "web-app-pod-1" in the "ingress-nginx" namespace to the local directory /tmp/bar.
Command: ```bash kubectl cp ingress-nginx/web-app-pod-1:/var/run/secrets/kubernetes.io/serviceaccount/ :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Con...
Embed the certificate authority data for the 'testing-cluster' cluster entry using the certificate authority file located at '~/.kube/cloud-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster testing-cluster --embed-certs --certificate-authority=~/.kube/cloud-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...
Taint nodes with label 'app-type=microservice' by adding a taint key 'special' with value 'storage-node-13' and effect 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l app-type=microservice special=storage-node-13: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": "",...
Start streaming the logs of the warp-drive container in the proxy-server-pod pod.
Command: ```bash kubectl logs -f -c warp-drive 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", "...
Update the annotation 'custom-label' of the pod 'cdn' with the value 'my-custom-value', replacing the existing value if any.
Command: ```bash kubectl annotate --overwrite pods cdn custom-label='my-custom-value' ``` 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...
Import the 'DATABASE_URL' key from the 'app-name-config' config map into the environment variables of the 'proxy-service-deployment' deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-name-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 def...
Execute the 'redis-cli' command inside the first pod of the 'search-service' service.
Command: ```bash kubectl exec svc/search-service -- 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, use the kube...
Create a service for the 'centos' deployment, which serves on port 9092 and connects to the containers on port 844300
Command: ```bash kubectl expose deployment centos --port=9092 --target-port=844300 ``` 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 specifi...
Forward data between local port 8888 and pod port 8080 in the log-aggregator-deployment deployment.
Command: ```bash kubectl port-forward deployment/log-aggregator-deployment 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 criteria, a pod wi...
Switch to raw terminal mode and attach to the web-app-pod container named lunar-launcher.
Command: ```bash kubectl attach web-app-pod -c lunar-launcher -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 omit...
import specific keys from a config map to a deployment by setting environment variables
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-config-dev deployment/user-management-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...
Copy the file '/tmp/foo' from the 'auth-service-pod-11' pod to the local machine at '/tmp/bar'
Command: ```bash kubectl cp kube-node-lease/auth-service-pod-11:/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 t...
Create a new config map named app-config-dev with the keys "conf" and "data" using the specified files "/path/to/configurations/file1.txt" and "/path/to/data/file2.txt" respectively.
Command: ```bash kubectl create configmap app-config-dev --from-file=conf=/path/to/configurations/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...
Create a new LoadBalancer service named auth-service-lb that will forward traffic from port 9092 to port 9090
Command: ```bash kubectl create service loadbalancer auth-service-lb --tcp=9092:9090 ``` 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", "de...
Import environment variables from a secret into a deployment.
Command: ```bash kubectl set env --from=secret/api-secret-key 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 variable definitions in one or mo...
Execute the 'node' command in the 'code-explorer' container of the 'database-pod' pod
Command: ```bash kubectl exec database-pod -c code-explorer -- node ``` 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...
Create a job with a specific command by using the kubectl create job command.
Command: ```bash kubectl create job certificate-renewal --image=jenkins -- java -jar /usr/share/jenkins/jenkins.war ``` 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", "d...
Add a taint to the node named 'k8s-node-1' with the key 'workload' and no value.
Command: ```bash kubectl taint nodes k8s-node-1 workload: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: j...
Create a service named "frontend" to expose the "media-stream-pod" pod on port 3306.
Command: ```bash kubectl expose pod media-stream-pod --port=3306 --name=frontend ``` 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...
Retrieve the previous terminated logs of the 'stardust-shuttle' container from the 'database-pod' pod
Command: ```bash kubectl logs -p -c stardust-shuttle database-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",...
Update the image of all containers in the 'namespace-3' DaemonSet to 'php:7.4.22'
Command: ```bash kubectl set image daemonset namespace-3 *=php:7.4.22 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `k...
Switch to raw terminal mode and attach to the 'mycontainer' container in the 'e-commerce-pod' pod.
Command: ```bash kubectl attach e-commerce-pod -c mycontainer -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 omit...
Create a secret named email-credentials-secret from an environment file.
Command: ```bash kubectl create secret generic email-credentials-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 ...
Forward local ports 3000 and 6000 to ports 8081 and 6000, respectively, in a pod selected by the deployment "log-aggregator-deployment".
Command: ```bash kubectl port-forward deployment/log-aggregator-deployment 3000 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 wi...
List the deployments in the "legacy-1.0.0" version of the "external-apps" API group and display the output in YAML format.
Command: ```bash kubectl get deployments.legacy-1.0.0.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 namespaced...
Scale the deployment named "baz" to a specific number of replicas.
Command: ```bash kubectl scale --current-replicas=3 --replicas=3 deployment/baz ``` 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 spec...
Retrieve the output from running the 'jenkins --version' command in the rocket-ranger container of the email-service-pod pod.
Command: ```bash kubectl exec email-service-pod -c rocket-ranger -- 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. ...
Scale the deployment named db-migration-replicaset from the current size of 5 to a new size of 7
Command: ```bash kubectl scale --current-replicas=5 --replicas=7 deployment/db-migration-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 --reso...
Copy the file "/tmp/foo" from the local machine to "/tmp/bar" in the remote pod "kube-proxy/load-balancer-pod-9" in the current namespace.
Command: ```bash kubectl cp :/tmp/foo kube-proxy/load-balancer-pod-9::/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 k...
Import the specific keys from a config map into the deployment of the user management.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-secrets deployment/user-management-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...
Forward local port 8081 to pod port 8088
Command: ```bash kubectl port-forward pod/api-service-pod 8081: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 selected au...
List the replication controller named "web", the service named "monitoring-rc", and the pod named "web-app-pod"
Command: ```bash kubectl get rc/web service/monitoring-rc pods/web-app-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 ...
Get the output from running the 'node' command inside the cdn-service-pod using the first container.
Command: ```bash kubectl exec cdn-service-pod -- node ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kube...
Start a wordpress pod with the nginx image, but override the spec with a partial set of values parsed from JSON
Command: ```bash kubectl run nginx --image=wordpress --overrides='{ "apiVersion": "stable-2.0.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] -...
Set the environment variable SMTP_HOST to "smtp.example.com" for all containers in all replication controllers
Command: ```bash kubectl set env rc --all SMTP_HOST=smtp.example.com ``` 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 templates (within replica...
Forward traffic from port 9090 on localhost and IP 10.19.21.23 to port 9090 in the security-service-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-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 th...
List the resources of different types by their names
Command: ```bash kubectl get rc/web service/log-aggregator-rc pods/security-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 i...
Create an ingress named 'www-ingress' with a rule that directs requests for website.com/input to svc1:8080
Command: ```bash kubectl create ingress www-ingress --rule="website.com/input=svc1:8080,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Copy the local file ~/.config/kube to the remote pod named task-processor-pod-17, specifically to the /etc/kubernetes directory, in the container named front-end-container.
Command: ```bash kubectl cp ~/.config/kube task-processor-pod-17:/etc/kubernetes -c front-end-container ``` 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 na...
Open the analytics-service object in the KUBE_EDITOR text editor, using gedit as the editor.
Command: ```bash KUBE_EDITOR="gedit" kubectl edit svc/analytics-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variab...
Create a cron job named 'report-generation' using the image 'mcr.microsoft.com/dotnet/core/runtime', with a schedule of running every minute
Command: ```bash kubectl create cronjob report-generation --image=mcr.microsoft.com/dotnet/core/runtime --schedule="*/1 * * * *" -- dotnet --list-runtimes ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` H...
Forward traffic from port 8080 on localhost and IP address 10.19.21.23 to port 8080 in the backend-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-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 criteri...
Forward the local port 8000 to port 5432 in the log-aggregator-pod pod.
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8000:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Retrieve the logs of the previous terminated 'lunar-launcher' container from the 'proxy-service-pod' pod.
Command: ```bash kubectl logs -p -c lunar-launcher proxy-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--containe...
Import the DEBUG_MODE key from the log-config config map and set it as an environment variable for the order-processing-deployment deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/log-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 variable definit...
Embed client certificate data for the "admin" entry in the kubeconfig file
Command: ```bash kubectl config set-credentials admin --client-certificate=~/.kube/admin.crt --embed-certs=true ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key...
Import the SMTP_SERVER key from the app-config-dev config map and set it as an environment variable for the api-server-deployment deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-config-dev 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 definiti...
Create a deployment named 'worker' with the image 'jenkins' and run the command 'java -jar /usr/share/jenkins/jenkins.war' inside the container.
Command: ```bash kubectl create deployment worker --image=jenkins -- java -jar /usr/share/jenkins/jenkins.war ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Retrieve the output of the 'dotnet --list-runtimes' command from the 'nano-bot' container inside the 'vpn-service-pod' pod.
Command: ```bash kubectl exec vpn-service-pod -c nano-bot -- 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 name. If...
Check if you have permission to list the job named "report-generation-job" in the "development" namespace
Command: ```bash kubectl auth can-i list jobs.batch/report-generation-job -n 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 part...
List the name and image of the containers in the web-app-pod pod in a custom format.
Command: ```bash kubectl get pod web-app-pod -o custom-columns=CONTAINER:.spec.containers[0].name,IMAGE:.spec.containers[0].image ``` 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 --sel...
Listen on your local machine's ports 8080 and 6000, forwarding data to/from ports 8888 and 6000 in the pod selected by the deployment named 'mydeployment'
Command: ```bash kubectl port-forward deployment/mydeployment 8080 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 selecte...
Add an annotation to a pod specified in the "docker-registry.yaml" file to indicate a security scan has passed.
Command: ```bash kubectl annotate -f docker-registry.yaml security-scan-status=pass ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and i...
Return the logs from the first container of the job named database-indexing-job
Command: ```bash kubectl logs job/database-indexing-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": ...
Add a taint to the node 'edge-node-10' with key 'special' and no value
Command: ```bash kubectl taint nodes edge-node-10 special: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: ...
Partially update a node by applying a strategic merge patch specified in YAML format.
Command: ```bash kubectl patch node worker-node-3 -p $'spec:\n type: LoadBalancer' ``` 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...
Create an ingress resource named 'api-v1-ingress' that routes traffic from 'website.com/module' to 'svc1:8088' using the TLS secret 'my-cert'
Command: ```bash kubectl create ingress api-v1-ingress --rule="website.com/module=svc1:8088,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Execute the 'python' command in the first container of the 'mydeployment' deployment and retrieve the output.
Command: ```bash kubectl exec deploy/mydeployment -- python ``` 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 kubect...
Update the label of the pod named 'proxy-server' with the label 'tier' and the value 'backend'.
Command: ```bash kubectl label pods proxy-server tier=backend ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usag...
Create an ingress with multiple hosts and set the pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="foo.com/path*=svc:27017" \ --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", ...
Set environment variables for a deployment by importing specific keys from a config map.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/env-vars 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 variable defin...
Create a deployment named 'jenkins-x' that runs the 'nginx' image and exposes port '8088'
Command: ```bash kubectl create deployment jenkins-x --image=nginx --port=8088 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of:...
Forward traffic from port 8888 on your local machine to port 8080 in the pod named 'proxy-server-pod'
Command: ```bash kubectl port-forward 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 criteria, a pod will be selected a...
Execute the command 'yum install -y aws-cli' in the 'quantum-quark' container of the 'api-service-pod' pod.
Command: ```bash kubectl exec api-service-pod -c quantum-quark -- yum install -y aws-cli ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container nam...
Listen on port 8081 on your local machine, forwarding traffic to port 8000 in the cdn-service-pod pod.
Command: ```bash kubectl port-forward 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 criteria, a pod will be selected au...
Switch to a raw terminal mode for a specific pod and container, and interact with the 'bash' shell from the pod.
Command: ```bash kubectl attach e-commerce-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 om...
Create an ingress named "public-service-ingress" that routes requests to website.com/example to svc1:9092
Command: ```bash kubectl create ingress public-service-ingress --rule="website.com/example=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 new ExternalName service named external-third-party-api-service that maps to the external name test-site.org
Command: ```bash kubectl create service externalname external-third-party-api-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 referenc...
Forward local port 8888 to port 6379 in the backend-pod and listen for the forwarded traffic.
Command: ```bash kubectl port-forward pod/backend-pod 8888: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 automa...
Embed the certificate authority data for the 'cloud-cluster' cluster entry using the command 'kubectl config set-cluster cloud-cluster --embed-certs --certificate-authority=~/.kube/my-k8s-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster cloud-cluster --embed-certs --certificate-authority=~/.kube/my-k8s-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 ...
Add a taint with the key 'app' on nodes that have the label release=beta
Command: ```bash kubectl taint node -l release=beta app=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": "", "usage": "Output f...
Create a role named "default_role" with the following permissions:
Command: ```bash kubectl create role default_role --verb=create --resource=pods --resource-name=billing-service --resource-name=image-processor ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-ru...
Copy the "/var/run/secrets/kubernetes.io/serviceaccount/" directory from the "logging/admin-dashboard-pod-16" pod to the local "/tmp/bar" directory.
Command: ```bash kubectl cp logging/admin-dashboard-pod-16:/var/run/secrets/kubernetes.io/serviceaccount/ :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "...
Copy the file 'foo' from the '/tmp' directory of the 'database-pod-2' pod in the 'argocd' namespace to the '/tmp/bar' directory on your local machine.
Command: ```bash kubectl cp argocd/database-pod-2:/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 kubectl.kube...
Import environment variables from a config map with a specific prefix for a deployment
Command: ```bash kubectl set env --from=configmap/app-settings --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 definition...
List deployments in YAML format using the "custom-version" of the "experimental-apps" API group.
Command: ```bash kubectl get deployments.custom-version.experimental-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 name...