prompt
stringlengths
13
282
response
stringlengths
128
3.11k
import the 'max_connections' key from the 'app-config' config map and set it as an environment variable in the 'proxy-service-deployment' deployment
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-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 defin...
Generate YAML for the modified deployment without actually making changes on the server
Command: ```bash kubectl set env deployment/mydeployment MONGO_URI=mongodb://localhost:27017/mydb -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 ...
Set the service account of the frontend-deployment to my-service-account
Command: ```bash kubectl set serviceaccount deployment frontend-deployment my-service-account ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax:...
Create a single ingress called 'private-ingress' that directs requests to testing.com/bar to the service 'svc1' on port 8000, using the TLS secret 'my-cert'
Command: ```bash kubectl create ingress private-ingress --rule="testing.com/bar=svc1:8000,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...
Rename the context 'on-prem-context' to 'edge-context' in your kubeconfig file
Command: ```bash kubectl config rename-context on-prem-context edge-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will also...
Start a pod named 'hazelcast' using the 'jenkins' image, and expose port 9000.
Command: ```bash kubectl run hazelcast --image=jenkins --port=9000 ``` 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": "--...
Add a taint with key 'environment' on nodes having label version=v1.0.0
Command: ```bash kubectl taint node -l version=v1.0.0 environment=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": "", "u...
Listen on port 9090 on localhost as well as the IP address 10.19.21.23 and forward the traffic to port 9090 in the pod named 'mypod'
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 9090:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a p...
List the environment variables defined on the 'proxy-service-deployment'
Command: ```bash kubectl set env deployment/proxy-service-deployment --list ``` 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 ...
Create a job named 'audit-job' using the 'wordpress' image and run the command 'apache2ctl -D FOREGROUND' inside the container
Command: ```bash kubectl create job audit-job --image=wordpress -- apache2ctl -D FOREGROUND ``` 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": "O...
Partially update the node named 'node-2' using a strategic merge patch
Command: ```bash kubectl patch node node-2 -p $'spec:\n someField: newValue' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful flags...
Get the output from running the 'ash' command in the 'cyber-sleuth' container in the 'analytics-pod' pod.
Command: ```bash kubectl exec analytics-pod -c cyber-sleuth -- ash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
Create an ingress that routes requests to a specific service with TLS encryption.
Command: ```bash kubectl create ingress public-service-ingress --rule="foo.com/bar=svc1:8181,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": "", "u...
Copy the directory /var/run/secrets/kubernetes.io/serviceaccount/ from the monitoring-agent-pod-6 pod in the ingress-nginx namespace to the /etc/kubernetes directory locally.
Command: ```bash kubectl cp ingress-nginx/monitoring-agent-pod-6:/var/run/secrets/kubernetes.io/serviceaccount/ /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": ""...
List deployments in the "legacy-1.0.0" version of the "sandbox-apps" API group and display the output in JSON format
Command: ```bash kubectl get deployments.legacy-1.0.0.sandbox-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 namespaced ...
Create a new ClusterIP service named payment-service-clusterip, mapping port 3000 on the service to port 8083 on the target
Command: ```bash kubectl create service clusterip payment-service-clusterip --tcp=3000:8083 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o"...
List deployments in JSON output format, in the specified version and API group.
Command: ```bash kubectl get deployments.v1.0.0.api-v1 -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will onl...
Execute the 'python' command inside the 'warp-drive' container of the 'analytics-pod' pod.
Command: ```bash kubectl exec analytics-pod -c warp-drive -- 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 th...
Create an ingress called 'myapp-ingress' that directs requests from foo.com/input to svc1:27017. Use the tls secret "my-cert".
Command: ```bash kubectl create ingress myapp-ingress --rule="foo.com/input=svc1:27017,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":...
View the metrics for pods with the label "project=project-alpha"
Command: ```bash kubectl top pod -l project=project-alpha ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl top pod [...
Copy the file /tmp/foo from the pod monitoring-agent-pod-6 in the kube-public namespace to the /tmp/bar directory on your local machine
Command: ```bash kubectl cp kube-public/monitoring-agent-pod-6::/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 th...
Partially update the node "k8s-node-1" by setting the spec type to "LoadBalancer" using a strategic merge patch in JSON format
Command: ```bash kubectl patch node k8s-node-1 -p '{"spec":{"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]` Helpfu...
Get the output from running the 'java -jar /usr/share/jenkins/jenkins.war' command inside the cosmic-container in the auth-service-pod pod.
Command: ```bash kubectl exec auth-service-pod -c cosmic-container -- java -jar /usr/share/jenkins/jenkins.war ``` 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": "", "...
Apply a taint with key 'app' and value 'backend' and effect 'PreferNoSchedule' to the node 'gpu-node-12'
Command: ```bash kubectl taint nodes gpu-node-12 app=backend: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 format....
Delete pods and services with names "foo" and "security"
Command: ```bash kubectl delete pod,service foo security ``` 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. So...
Forward data between local ports 8000 and 8080 and the pod's ports 8080 and 6000 in the analytics-pod pod
Command: ```bash kubectl port-forward pod/analytics-pod 8000 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...
create a ClusterIP service with the name ldap-service-clusterip, mapping port 8080 on the service to port 5001 on the pods
Command: ```bash kubectl create service clusterip ldap-service-clusterip --tcp=8080:5001 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "...
Create an ingress called 'rontend-ingress' that directs requests to 'testing.com/bar' to 'svc1:6379' with a tls secret named "my-cert"
Command: ```bash kubectl create ingress rontend-ingress --rule="testing.com/bar=svc1:6379,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...
Set the CPU limit of the container named "nginx" in the "golang" deployment to "5" and the memory limit to "4Gi".
Command: ```bash kubectl set resources deployment golang -c=nginx --limits=cpu=5,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...
Execute the 'go run hello.go' command in the cyber-sleuth container of the media-stream-pod pod and get the output.
Command: ```bash kubectl exec media-stream-pod -c cyber-sleuth -- go run hello.go ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Create an ingress resource called 'default-ingress' that directs requests to site.com/example to the service named 'svc1' on port 9091, using the TLS secret named 'my-cert'
Command: ```bash kubectl create ingress default-ingress --rule="site.com/example=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": "", "usa...
Scale the deployment named "web" to 7 replicas, if its current size is 5.
Command: ```bash kubectl scale --current-replicas=5 --replicas=7 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...
Set a custom TLS server name for the "staging-cluster" cluster
Command: ```bash kubectl config set-cluster staging-cluster --tls-server-name=galaxy-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certif...
Create a pod named "hazelcast" using the "wordpress" image and expose port 5001
Command: ```bash kubectl run hazelcast --image=wordpress --port=5001 ``` 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": "...
Forward ports 8088 and 6000 locally to ports 8088 and 6000 in the pod
Command: ```bash kubectl port-forward pod/frontend-pod 8088 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 autom...
execute the 'redis-server' command in the first container of the database-pod and get the output
Command: ```bash kubectl exec database-pod -- redis-server ``` 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...
Create a job named 'scaling-job' using the 'mongo' image, and run the command 'mongo --version' inside the job
Command: ```bash kubectl create job scaling-job --image=mongo -- mongo --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output forma...
Set the service account of the deployment named cache-cluster-deployment to kube-proxy.
Command: ```bash kubectl set serviceaccount deployment cache-cluster-deployment kube-proxy ``` 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: `k...
Execute the command "java -jar /usr/share/jenkins/jenkins.war" inside the pod named media-stream-pod and retrieve the output.
Command: ```bash kubectl exec media-stream-pod -- java -jar /usr/share/jenkins/jenkins.war ``` 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 a new pod named 'nginx' using the 'amazonlinux' image, but customize the pod's specifications by providing a partial set of values parsed from the specified JSON file.
Command: ```bash kubectl run nginx --image=amazonlinux --overrides='{ "apiVersion": "v1.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...
Copy the '/var/run/secrets/kubernetes.io/serviceaccount/' file from the local machine to the '/tmp/bar_dir' directory inside the 'cert-manager/metrics-exporter-pod-10' pod in the specified namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ cert-manager/metrics-exporter-pod-10:/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": "", "...
Copy the file "foo" from the local machine to the remote pod "logging-agent-pod-7" in the namespace "kube-node-lease" and place it at the location "/tmp/bar".
Command: ```bash kubectl cp :/tmp/foo kube-node-lease/logging-agent-pod-7::/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 ...
Attach to the email-service-pod container named quantum-quark in interactive terminal mode
Command: ```bash kubectl attach email-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...
Execute the command 'geth attach' inside the first container of the first pod running the 'payment-service' service.
Command: ```bash kubectl exec svc/payment-service -- geth attach ``` 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...
Update the environment variable 'GOOGLE_API_KEY' for the deployment 'proxy-service-deployment'
Command: ```bash kubectl set env deployment/proxy-service-deployment GOOGLE_API_KEY=your-google-api-key ``` 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...
Update the environment variables of the specified deployment by importing specific keys from a config map.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/api-config deployment/analytics-platform-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...
Execute 'psql' command in the first container of the 'monitoring-service' service.
Command: ```bash kubectl exec svc/monitoring-service -- psql ``` 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 kubec...
Listen on port 8888 locally and forward the traffic to port 5000 in the pod 'cdn-service-pod'
Command: ```bash kubectl port-forward pod/cdn-service-pod 8888:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Forward local port 5000 to port 6379 in the pod "frontend-pod"
Command: ```bash kubectl port-forward pod/frontend-pod 5000:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Import specific keys from a config map into an environment variable of a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-name-config deployment/web-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 defin...
Delete pods and services named "security" and "chat-app"
Command: ```bash kubectl delete pod,service security chat-app ``` 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 selecto...
Embed the certificate authority data for the cluster entry "dev-cluster"
Command: ```bash kubectl config set-cluster dev-cluster --embed-certs --certificate-authority=~/.kube/staging-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 s...
Configure the TLS server name for the staging-cluster cluster entry as "web-cluster"
Command: ```bash kubectl config set-cluster staging-cluster --tls-server-name=web-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifica...
Create a single ingress called 'web-ingress' that directs requests to foo.com/input to the service 'svc1' running on port 7000
Command: ```bash kubectl create ingress web-ingress --rule="foo.com/input=svc1:7000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Set the environment variables of the scheduler-app-deployment deployment using the values from the azure-storage-secret secret.
Command: ```bash kubectl set env --from=secret/azure-storage-secret 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 definitions in one or...
View the CPU and memory metrics for all pods in the "external-security-service" namespace.
Command: ```bash kubectl top pod --namespace=external-security-service ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kube...
Create a cluster role binding for multiple users and a group using a specific cluster role
Command: ```bash kubectl create clusterrolebinding foo --clusterrole=foo --user=user1 --user=user2 --group=group1 ``` What it does: Create a cluster role binding for a particular cluster role. Syntax: `kubectl create clusterrolebinding NAME --clusterrole=NAME [--user=username] [--group=groupname] [--serviceaccount=na...
Run the 'wp' command in the vpn-service-pod pod and get the output
Command: ```bash kubectl exec vpn-service-pod -- wp ``` 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.kubern...
Get the output from running the 'apache2ctl -D FOREGROUND' command inside the 'time-machine' container of the 'gateway-pod' pod
Command: ```bash kubectl exec gateway-pod -c time-machine -- apache2ctl -D FOREGROUND ``` 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. ...
Forward local port 8080 to port 8081 in the pod with name 'frontend-pod'
Command: ```bash kubectl port-forward pod/frontend-pod 8080: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 autom...
Apply all resources in the directory "dir/" using the configurations specified in the "kustomization.yaml" file
Command: ```bash kubectl apply -k dir/ ``` What it does: Apply a configuration to a resource by file name or stdin. The resource name must be specified. This resource will be created if it doesn't exist yet. To use 'apply', always create the resource initially with either 'apply' or 'create --save-config'. JSON and YA...
Copy the file "/tmp/foo" from the pod "kube-proxy/task-processor-pod-17" to the local directory "/etc/kubernetes".
Command: ```bash kubectl cp kube-proxy/task-processor-pod-17::/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 omitted, u...
Import the environment variables from the ldap-credentials-secret secret and apply them to the backend-microservice-deployment deployment.
Command: ```bash kubectl set env --from=secret/ldap-credentials-secret deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
List the deployments in YAML output format using the "v1.1.0" version of the "beta-apps" API group
Command: ```bash kubectl get deployments.v1.1.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 ...
Update the cluster role binding "admin" for the kube-scheduler service account in the "namespace" namespace
Command: ```bash kubectl set subject clusterrolebinding admin --serviceaccount=namespace:kube-scheduler ``` What it does: Update the user, group, or service account in a role binding or cluster role binding. Syntax: `kubectl set subject (-f FILENAME | TYPE NAME) [--user=username] [--group=groupname] [--serviceaccount...
Create a debug container named 'dgb-img' with the debian image, by copying the proxy-server-pod
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=dgb-img --image=debian --set-image=database=mysql:5.7,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and ...
Create a cron job named backup-job that runs every minute and executes the command "php --version"
Command: ```bash kubectl create cronjob backup-job --image=php --schedule="*/1 * * * *" -- php --version ``` 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 a debug copy of the "media-stream-pod" by adding a debug container and changing container images
Command: ```bash kubectl debug media-stream-pod -it --copy-to=my-custom-dbg --image=debian --set-image=logger=logging-app:debug,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 r...
Create a new ClusterIP service named database-service-clusterip that maps port 3001 on the local machine to port 8181 on the service
Command: ```bash kubectl create service clusterip database-service-clusterip --tcp=3001: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": "-o...
Dump the cluster information for the 'default' and 'kube-system' namespaces to the directory '/tmp/foo'
Command: ```bash kubectl cluster-info dump --namespaces default,kube-system --output-directory=/tmp/foo ``` What it does: Dump cluster information out suitable for debugging and diagnosing cluster problems. By default, dumps everything to stdout. You can optionally specify a directory with --output-directory. If you...
create a service for the 'alpine' deployment, which serves on port 8888 and connects to the containers on port 808200
Command: ```bash kubectl expose deployment alpine --port=8888 --target-port=808200 ``` 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...
Import the API_KEY key from the monitoring-config ConfigMap into the backend-microservice-deployment deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/monitoring-config deployment/backend-microservice-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...
Create a new config map named app-settings from the key=value pairs in the specified file
Command: ```bash kubectl create configmap app-settings --from-file=path/to/preferences ``` 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 key will default to the basen...
Create an ingress called 'internal-ingress' that directs requests to a specific path and service with TLS encryption.
Command: ```bash kubectl create ingress internal-ingress --rule="foo.com/example=svc1:5001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Copy the file "/tmp/foo" from the pod "security-scanner-pod-18" on the kube-server to the local "/etc/kubernetes" directory
Command: ```bash kubectl cp kube-server/security-scanner-pod-18::/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 omitted...
Get output from running the 'geth attach' command in the cosmic-container from the pod cdn-service-pod
Command: ```bash kubectl exec cdn-service-pod -c cosmic-container -- geth attach ``` 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 om...
Add a taint with key 'environment' on nodes having label role=database
Command: ```bash kubectl taint node -l role=database environment=dev-node-4: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 the config_file_path key from the global-config config map into the cache-cluster-deployment deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/global-config deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Create a new ClusterIP service named messaging-service-clusterip that maps port 9092 on the service to port 9092 on the pod
Command: ```bash kubectl create service clusterip messaging-service-clusterip --tcp=9092:9092 ``` 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": "-...
Delete the security-user user from the kubectl configuration.
Command: ```bash kubectl config delete-user security-user ``` What it does: Delete the specified user from the kubeconfig. Syntax: `kubectl config delete-user NAME`
Forward local port 6379 to pod port 6379
Command: ```bash kubectl port-forward pod/api-service-pod 6379:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Create a deployment named "cache" using the "ubuntu" image and expose port 7000
Command: ```bash kubectl create deployment cache --image=ubuntu --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: js...
Create a job named "report-generation-job" using the "mongo" image, and run the command "mongo --version" within the job
Command: ```bash kubectl create job report-generation-job --image=mongo -- mongo --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Ou...
Execute the command 'jenkins --version' in the 'time-machine' container of the 'vpn-service-pod' pod.
Command: ```bash kubectl exec vpn-service-pod -c time-machine -- 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 ...
Update the pod named 'security' by adding the annotation 'scaling-policy' with the value 'auto-horizontal-scaling'
Command: ```bash kubectl annotate pods security scaling-policy=auto-horizontal-scaling ``` 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...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-settings deployment/backend-microservice-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...
Run the 'go run hello.go' command in the lunar-launcher container of the cdn-service-pod pod and get the output.
Command: ```bash kubectl exec cdn-service-pod -c lunar-launcher -- go run hello.go ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If ...
Create a new LoadBalancer service named web-app-lb that maps port 8082 on the host machine to port 5432 on the pods.
Command: ```bash kubectl create service loadbalancer web-app-lb --tcp=8082:5432 ``` 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", "default...
Forward port 8888 on all addresses to port 8088 in the backend-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8888:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will ...
Copy the file /tmp/foo from the remote pod named worker-pod-4 in the prometheus namespace to /etc/kubernetes locally.
Command: ```bash kubectl cp prometheus/worker-pod-4::/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 omitted, use the ku...
Set a custom TLS server name for the data-cluster in the configuration.
Command: ```bash kubectl config set-cluster data-cluster --tls-server-name=testing-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certific...
Add a taint with key 'cpu-type' and no value to the 'node-2' node.
Command: ```bash kubectl taint nodes node-2 cpu-type:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|...
Remove a label named 'tier' from the pod named 'gateway'
Command: ```bash kubectl label pods gateway tier- ``` 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...
Import environment from a secret
Command: ```bash kubectl set env --from=secret/docker-registry-secret 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 definitions in one ...
Execute the command 'mysql --version' in the container 'mycontainer' within the pod 'database-pod' and display the output
Command: ```bash kubectl exec database-pod -c mycontainer -- mysql --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 omitte...
Annotate a pod in the "docker-registry.yaml" file with a deployment script URL.
Command: ```bash kubectl annotate -f docker-registry.yaml 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 ...
Create a service for the replication controller specified in the "nginx-controller.yaml" file, exposing it on port 8082 and connecting to the containers on port 330600.
Command: ```bash kubectl expose -f nginx-controller.yaml --port=8082 --target-port=330600 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the ...
List deployments in YAML output format for the "api-v2" API group in the "hotfix-1.1.2" version
Command: ```bash kubectl get deployments.hotfix-1.1.2.api-v2 -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 wi...
Create a job named "certificate-renewal" using the image "confluentinc/cp-kafka" that runs the command "kafka-topics --list"
Command: ```bash kubectl create job certificate-renewal --image=confluentinc/cp-kafka -- kafka-topics --list ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default"...
Taint the nodes with label 'app=web-app' by adding the taint 'hardware=dev-node-4:PreferNoSchedule'
Command: ```bash kubectl taint node -l app=web-app hardware=dev-node-4: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": "Out...