prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Copy the local file "/tmp/foo" to the remote pod "ingress-controller-pod-8" in the "openfaas" namespace, placing it in the "/etc/kubernetes" directory.
Command: ```bash kubectl cp /tmp/foo openfaas/ingress-controller-pod-8:/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 omitted, u...
Create a new ingress called 'app2-ingress' with a rule that directs requests from 'testing.com/input' to service 'svc1' on port '8083'
Command: ```bash kubectl create ingress app2-ingress --rule="testing.com/input=svc1:8083,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...
Check if the current user has permission to list the "virus-scan-job" job in the "default" namespace
Command: ```bash kubectl auth can-i list jobs.batch/virus-scan-job -n default ``` 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 tha...
Scale the deployment named staging-app-rs to 3 replicas, if its current size is equal to 7
Command: ```bash kubectl scale --current-replicas=7 --replicas=3 deployment/staging-app-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-vers...
Scale the deployment named app-v2-replicaset to 5 replicas if its current size is 1
Command: ```bash kubectl scale --current-replicas=1 --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...
Set the resource request and limits for all containers in the kafka deployment
Command: ```bash kubectl set resources deployment kafka --limits=cpu=200m,memory=512Mi --requests=cpu=500m,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requeste...
Add a label to the pod named 'api' with the key 'app' and the value 'myapp'
Command: ```bash kubectl label pods api app=myapp ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If true...
Execute the command 'kafka-server-start /etc/kafka/server.properties' in the 'nebula-navigator' container of the 'monitoring-pod' pod and get the output.
Command: ```bash kubectl exec monitoring-pod -c nebula-navigator -- kafka-server-start /etc/kafka/server.properties ``` 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": ...
Copy the '~/.config/kube' file from the 'default/api-server-pod-3' pod to the '/tmp/bar' directory on your local machine
Command: ```bash kubectl cp default/api-server-pod-3:~/.config/kube /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kub...
Start a WordPress pod named hazelcast with the image wordpress and expose port 5000
Command: ```bash kubectl run hazelcast --image=wordpress --port=5000 ``` 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": "...
Get the output from running the `mongo --version` command on the first pod of the `monitoring-service` service, using the first container.
Command: ```bash kubectl exec svc/monitoring-service -- 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. If omitted, us...
Get the output of the "docker run -it ubuntu" command from the pod named "vpn-service-pod" using the container named "stardust-shuttle"
Command: ```bash kubectl exec vpn-service-pod -c stardust-shuttle -- docker run -it ubuntu ``` 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 n...
Create an ingress resource called 'public-service-ingress' with a rule that directs requests from website.com/input to the service 'svc1' on port 8081
Command: ```bash kubectl create ingress public-service-ingress --rule="website.com/input=svc1:8081,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ...
Scale the deployment named web to 5 replicas only if its current size is 1.
Command: ```bash kubectl scale --current-replicas=1 --replicas=5 deployment/web ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is spec...
Return the snapshot logs from the container 'payment-gateway-pod-1' of the deployment 'notification-handler-deployment'
Command: ```bash kubectl logs deployment/notification-handler-deployment -c payment-gateway-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]` Helpf...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/security-service-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 names...
Create a new config map named app-config-dev by specifying keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-dev --from-file=properties=/path/to/settings/file1.txt --from-file=key1=/path/to/settings/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creati...
Execute the command 'php --version' inside the first container of the first pod of the deployment 'analytics-platform-deployment'
Command: ```bash kubectl exec deploy/analytics-platform-deployment -- php --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If...
Update the node 'k8s-node-1' by adding a taint with key 'zone', value 'us-west-1a', and effect 'PreferNoSchedule'
Command: ```bash kubectl taint nodes k8s-node-1 zone=us-west-1a: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 form...
Create a new config map named app-config-prod using specified keys and file paths
Command: ```bash kubectl create configmap app-config-prod --from-file=conf=/path/to/data/file1.txt --from-file=data=/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 confi...
Create a copy of the 'proxy-server-pod' resource and add a debug container and change container images.
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=debug-image-memcached --image=debian --set-image=logger=logging-app:debug,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects ident...
Create an ingress named 'ingsecret' with TLS enabled, using the secret named 'secret1'
Command: ```bash kubectl create ingress ingsecret --class=default \ --rule="foo.com/*=svc:9092,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": "--output", "short": "-o", "default": "", ...
Update the nginx container image from the local file located at path/to/file.yaml to openjdk:16.0.2
Command: ```bash kubectl set image -f path/to/file.yaml openjdk=openjdk:16.0.2 --local -o yaml ``` 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), re...
Apply a taint on nodes with label app=web-app
Command: ```bash kubectl taint node -l app=web-app datacenter=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": "", "usage...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=LOG_LEVEL --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 a copy of the chat-app-pod with a debug container and change the container images to 'debian' and 'mysql:5.7' respectively
Command: ```bash kubectl debug chat-app-pod -it --copy-to=debug-image-memcached --image=debian --set-image=database=mysql:5.7,database=mysql:5.7 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by res...
Forward local port 8000 to port 8888 in the pod 'web-app-pod'
Command: ```bash kubectl port-forward pod/web-app-pod 8000: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 automa...
Create a cron job called "data-processing" with the image "mysql", scheduled to run every minute, and executing the command "mysqld".
Command: ```bash kubectl create cronjob data-processing --image=mysql --schedule="*/1 * * * *" -- mysqld ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "...
Create an ingress called 'public-ingress' that directs requests to testing.com/module to svc1:3000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress public-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": "", "us...
Set the service account of the deployment named "proxy-service-deployment" to "kube-scheduler"
Command: ```bash kubectl set serviceaccount deployment proxy-service-deployment kube-scheduler ``` 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...
Stream the logs of the stardust-shuttle container in the payment-gateway-pod pod
Command: ```bash kubectl logs -f -c stardust-shuttle payment-gateway-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": "--cont...
Taint nodes with release=beta label with datacenter=app-node-6:PreferNoSchedule
Command: ```bash kubectl taint node -l release=beta datacenter=app-node-6: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": "...
Get the output from running the 'node' command in the time-machine container of the vpn-service-pod pod.
Command: ```bash kubectl exec vpn-service-pod -c time-machine -- 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 ...
Set resource request and limits for containers in Jenkins deployment
Command: ```bash kubectl set resources deployment jenkins --limits=cpu=200m,memory=512Mi --requests=cpu=100m,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 reques...
List the replication controller 'web', the service 'proxy-server-rc', and the pod 'vpn-service-pod'
Command: ```bash kubectl get rc/web service/proxy-server-rc pods/vpn-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 names...
List deployments in the YAML output format for the "v3.0.0" version of the "third-party-apps" API group.
Command: ```bash kubectl get deployments.v3.0.0.third-party-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 yo...
Forward local traffic on port 8000 to port 8888 in a pod selected by the analytics-platform-deployment deployment.
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 8000 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 po...
Forward connections from port 8080 on all addresses to port 8080 of the pod named "api-service-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-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 w...
Create a deployment named 'nats' using the 'amazonlinux' image and expose port 7000
Command: ```bash kubectl create deployment nats --image=amazonlinux --port=7000 ``` 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...
Output a modified deployment in YAML format without affecting the running deployment on the server.
Command: ```bash kubectl set env deployment/analytics-platform-deployment ENV=prod -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 tem...
Run the 'irb' command in the rocket-ranger container of the log-aggregator-pod pod and get the output
Command: ```bash kubectl exec log-aggregator-pod -c rocket-ranger -- 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 deployment named gateway using the confluentinc/cp-kafka image and exposing port 8181.
Command: ```bash kubectl create deployment gateway --image=confluentinc/cp-kafka --port=8181 ``` 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 f...
Update the compliance level annotation of a pod identified by type and name in the "parameters.json" file.
Command: ```bash kubectl annotate -f parameters.json compliance-level=PCI-DSS ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include...
Set the client-key-data field of the saas-admin user with a specified certificate data using the --set-raw-bytes option
Command: ```bash kubectl config set users.saas-admin.client-key-data cert_data_here --set-raw-bytes=true ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALU...
Add a custom label to a pod defined in the "docker-registry.yaml" file.
Command: ```bash kubectl annotate -f docker-registry.yaml 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 an...
Create a service for the php replication controller specified in the "php-controller.yaml" file
Command: ```bash kubectl expose -f php-controller.yaml --port=5432 --target-port=909000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the sp...
Create a service for the replication controller specified in the "ruby-controller.yaml" file
Command: ```bash kubectl expose -f ruby-controller.yaml --port=8082 --target-port=500100 ``` 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 s...
Embed the certificate authority data for the 'sun-cluster' cluster entry using the command: 'kubectl config set-cluster sun-cluster --embed-certs --certificate-authority=~/.kube/cluster-gamma/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster sun-cluster --embed-certs --certificate-authority=~/.kube/cluster-gamma/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...
Partially update the web-node-8 node by applying a strategic merge patch that sets the "type" field to "LoadBalancer".
Command: ```bash kubectl patch node web-node-8 -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 fl...
Expose a replication controller as a service with a specific port configuration
Command: ```bash kubectl expose -f wordpress-controller.yaml --port=5432 --target-port=818100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on ...
Create a job named "backup" with the nginx image, and run the command "nginx -g 'daemon off;'" inside the job
Command: ```bash kubectl create job backup --image=nginx -- nginx -g "daemon off;" ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output for...
Create a job called log-processing-job using the redis image and run the redis-cli command inside the job.
Command: ```bash kubectl create job log-processing-job --image=redis -- redis-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 form...
List deployments in YAML output format using the "v3.0.0" version of the "beta-apps" API group.
Command: ```bash kubectl get deployments.v3.0.0.beta-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 you will ...
List deployments in YAML output format, in the "v1.1.0" version of the "third-party-apps" API group.
Command: ```bash kubectl get deployments.v1.1.0.third-party-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 yo...
Create a service for the replicated hazelcast which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rc hazelcast --port=8000 --target-port=808900 ``` 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...
Copy the `~/.config/kube` file from the `cert-manager/cache-pod-5` pod to the `/etc/kubernetes` directory on your local machine.
Command: ```bash kubectl cp cert-manager/cache-pod-5:~/.config/kube /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 omitted, use ...
Create a pod disruption budget named "worker-pdb" that selects all pods with the label "role=worker" and ensures that at least 9 of them are available at any given time.
Command: ```bash kubectl create poddisruptionbudget worker-pdb --selector=role=worker --min-available=9 ``` 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 [--dry-...
Retrieve snapshot logs from the container "frontend-pod-1" of the deployment "mydeployment".
Command: ```bash kubectl logs deployment/mydeployment -c frontend-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: "flag": "--conta...
Run the 'dotnet --list-sdks' command on the cyber-sleuth container of the analytics-pod and retrieve the output.
Command: ```bash kubectl exec analytics-pod -c cyber-sleuth -- 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 o...
Update the label of pod 'frontend' to 'release=v2.0'
Command: ```bash kubectl label pods frontend release=v2.0 ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": ...
Create a new pod named "nginx" using the "mongo" image, and customize the pod specification by providing overrides in JSON format.
Command: ```bash kubectl run nginx --image=mongo --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] -- [C...
remove the pods and services named "proxy" and "backend"
Command: ```bash kubectl delete pod,service proxy backend ``` 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. S...
Copy the local file /tmp/foo to the remote pod front-end-pod-12 in the namespace kube-proxy, and place it in the /tmp/bar directory.
Command: ```bash kubectl cp /tmp/foo kube-proxy/front-end-pod-12:/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 kubect...
Expose the centos deployment as a service on port 3000, connecting to the containers on port 808900
Command: ```bash kubectl expose deployment centos --port=3000 --target-port=808900 ``` 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...
Check if you have permissions to list the job named "data-migration-job" in the "testing" namespace
Command: ```bash kubectl auth can-i list jobs.batch/data-migration-job -n testing ``` 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...
Execute the command 'php --version' in the 'code-explorer' container of the 'security-service-pod' pod.
Command: ```bash kubectl exec security-service-pod -c code-explorer -- php --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. I...
Copy a directory from a remote pod to a local directory.
Command: ```bash kubectl cp kube-proxy/monitoring-agent-pod-6:/tmp/foo_dir /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, ...
Create a new secret named 'password-secret' using the configurations from the 'configurations.env' file
Command: ```bash kubectl create secret generic password-secret --from-env-file=path/to/configurations.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...
Delete a pod using a manifest file specified in preferences.json
Command: ```bash kubectl delete -f ./preferences.json ``` 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. Some ...
Copy the local file /var/run/secrets/kubernetes.io/serviceaccount/ to the remote pod ingress-controller-pod-8, in the container front-end-container, at the path /tmp/bar.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ ingress-controller-pod-8::/tmp/bar -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...
Open the 'email-service' service for editing using the vim editor.
Command: ```bash KUBE_EDITOR="vim" kubectl edit svc/email-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, o...
Set environment variables for the "prod-user" entry in exec auth plugin
Command: ```bash kubectl config set-credentials prod-user --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 Bea...
Forward port 6379 on your local machine to port 9090 on the backend-pod.
Command: ```bash kubectl port-forward pod/backend-pod 6379: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...
Forward port 5432 from the pod frontend-pod to port 5432 on all addresses
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 5432: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...
Check the status of a deployment rollout in staging environment
Command: ```bash kubectl rollout status deployment/staging ``` What it does: Show the status of the rollout. By default 'rollout status' will watch the status of the latest rollout until it's done. If you don't want to wait for the rollout to finish then you can use --watch=false. Note that if a new rollout starts in-...
Create a new ClusterIP service named 'inventory-service-clusterip' that forwards traffic from port 3306 to port 8181
Command: ```bash kubectl create service clusterip inventory-service-clusterip --tcp=3306:8181 ``` 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": "-...
Create a copy of the cdn-service-pod and add a debug container to it, while also changing container images for the debug container and scheduler and logger containers.
Command: ```bash kubectl debug cdn-service-pod -it --copy-to=debug-image-web --image=debian --set-image=scheduler=my-scheduler:1.0,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identi...
Set the CPU and memory limits for the container in the deployment "runtime" to 5 and 512Mi respectively.
Command: ```bash kubectl set resources deployment runtime -c=nginx --limits=cpu=5,memory=512Mi ``` 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 ...
Create an ingress called 'app2-ingress' that directs requests to 'testing.com/module' to 'svc1:9091' with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="testing.com/module=svc1:9091,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create a new namespace named namespace-1
Command: ```bash kubectl create namespace namespace-1 ``` What it does: Create a namespace with the specified name. Syntax: `kubectl create namespace NAME [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|go-template|go-te...
Copy directory from remote pod to local directory
Command: ```bash kubectl cp cert-manager/backend-pod-13:/tmp/foo_dir :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the k...
List resources of different types by providing their names
Command: ```bash kubectl get rc/web service/monitoring-rc pods/auth-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 namesp...
Import specific keys from a config map into a deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/kube-system-config deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Create a role named "default_role" with ResourceName specified
Command: ```bash kubectl create role default_role --verb=connect --resource=pods --resource-name=log-aggregator --resource-name=queue-consumer ``` 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...
Start a pod named "hazelcast" with the "postgres" image and expose port 3306 for container communication.
Command: ```bash kubectl run hazelcast --image=postgres --port=3306 ``` 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": "-...
Import the "secret_key" key from the config map "app-settings" into the "database-deployment" deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-settings deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions i...
Copy the ~/.config/kube local file to the /tmp/bar directory in the argocd/monitoring-agent-pod-6 pod in the current namespace
Command: ```bash kubectl cp ~/.config/kube argocd/monitoring-agent-pod-6::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Import the 'my-example-key' keys from the 'configmap/app-config' config map into the 'scheduler-app-deployment' deployment.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-config deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Forward local traffic from port 5000 to port 8081 in the analytics-platform-deployment pod.
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 5000 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a po...
List deployments in JSON output format, specifically from the "stable-2.0.0" version of the "third-party-apps" API group.
Command: ```bash kubectl get deployments.stable-2.0.0.third-party-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespa...
Update a pod in "preferences.json" by adding an annotation with the deployment-script URL
Command: ```bash kubectl annotate -f preferences.json 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 larg...
Remove the label 'bar' from the pod 'chat-app'
Command: ```bash kubectl label pods chat-app app- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If true...
Set the cpu limits of the nginx container in the centos deployment to "1" and memory limits to "4Gi".
Command: ```bash kubectl set resources deployment centos -c=nginx --limits=cpu=1,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to its...
Create a new ExternalName service named external-metrics-service, with the external name set to "practice-online.site"
Command: ```bash kubectl create service externalname external-metrics-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...
Attach to a specific container within a pod and interact with its output.
Command: ```bash kubectl attach backend-pod -c mycontainer ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Start a new pod named 'hazelcast' with the mysql image where the container exposes port 7000.
Command: ```bash kubectl run hazelcast --image=mysql --port=7000 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--fi...
Import the keys EXTERNAL_API_URL from the config map app-secrets and set them as environment variables in the deployment named proxy-service-deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-secrets 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...
Update the resource limits of the nginx container in the go deployment to set the CPU limit to "10" and the memory limit to "512Mi".
Command: ```bash kubectl set resources deployment go -c=nginx --limits=cpu=10,memory=512Mi ``` 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 its ...
Update the label of pod 'security' with the label 'tier' set to 'backend'
Command: ```bash kubectl label pods security 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", "usage": ...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ file from the local machine to the /tmp/bar directory in a remote pod named admin-dashboard-pod-16 in the default namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ default/admin-dashboard-pod-16:/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "C...