prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Import specific keys from a config map
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/monitoring-config deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Create a cluster role named "default_role" with permissions to update the specified resource names.
Command: ```bash kubectl create clusterrole default_role --verb=update --resource=configmaps --resource-name=error-logger --resource-name=message-queue ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=serv...
Switch to raw terminal mode and attach to the email-service-pod container named nebula-navigator.
Command: ```bash kubectl attach email-service-pod -c nebula-navigator -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....
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-secrets 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...
Create a service for a python application using replica set, which serves on port 8080 and connects to the containers on port 8181
Command: ```bash kubectl expose rs python --port=8080 --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 the specified port....
Set the CPU limits to "100m" and memory limits to "256Mi" for the WordPress container in the deployment named "wordpress"
Command: ```bash kubectl set resources deployment wordpress -c=nginx --limits=cpu=100m,memory=256Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst u...
Show metrics for a specific pod and its containers
Command: ```bash kubectl top pod frontend-pod --containers ``` 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 ...
Run the command 'yum install -y wget' inside the gateway-pod pod, using the first container by default.
Command: ```bash kubectl exec gateway-pod -- yum install -y wget ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the k...
Update the password of the testing-node-11 node by applying a strategic merge patch with the following JSON:
Command: ```bash kubectl patch node testing-node-11 -p '{"stringData":{"password":"new-password"}' ``` 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...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/global-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 defin...
Return the snapshot logs from the container monitoring-stack-deployment-1 of the web-app-pod deployment.
Command: ```bash kubectl logs deployment/monitoring-stack-deployment -c web-app-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: "f...
Get output of 'ash' command in first pod of 'order-processing-deployment' deployment
Command: ```bash kubectl exec deploy/order-processing-deployment -- 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, us...
Create a copy of the "frontend-pod" with all container images changed to "python" for debugging
Command: ```bash kubectl debug frontend-pod --copy-to=debug-image-api --set-image=*=python ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no res...
Retrieve the snapshot logs from the container named 'payment-gateway-pod-1' in the deployment 'search-engine-deployment'
Command: ```bash kubectl logs deployment/search-engine-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]` Helpful flag...
Set a custom TLS server name for the sun-cluster Kubernetes cluster entry
Command: ```bash kubectl config set-cluster sun-cluster --tls-server-name=prod-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-...
Forward local port 8000 to port 8000 in the security-service-pod pod
Command: ```bash kubectl port-forward pod/security-service-pod 8000:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Execute the 'ash' command in the 'lunar-launcher' container of the 'e-commerce-pod' pod and get the output.
Command: ```bash kubectl exec e-commerce-pod -c lunar-launcher -- 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 ...
Forward traffic from a local port to a specific port in a pod
Command: ```bash kubectl port-forward pod/backend-pod :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 automatica...
Update the scaling policy of a pod with the values specified in the "params.json" file.
Command: ```bash kubectl annotate -f params.json 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 a...
Get output from running the 'irb' command in the 'warp-drive' container inside the 'vpn-service-pod' pod.
Command: ```bash kubectl exec vpn-service-pod -c warp-drive -- 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, use the...
Update the image of all containers in the daemonset named 'namespace-2' to 'mysql:5.7.35'
Command: ```bash kubectl set image daemonset namespace-2 *=mysql:5.7.35 ``` 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: ...
Expose a replica set as a service, serving on port 8084 and connecting to the containers on port 818100.
Command: ```bash kubectl expose rs alpine --port=8084 --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 the specified port....
Forward port 3000 on all addresses to port 6379 in the pod named "mypod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 3000: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 sel...
Create a cluster role named "bar" with the permission to proxy services and access specific resource names such as "keycloak-server" and "identity-provider"
Command: ```bash kubectl create clusterrole bar --verb=proxy --resource=services --resource-name=keycloak-server --resource-name=identity-provider ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cl...
Add a taint with the key 'zone' on nodes that have the label 'environment=production'
Command: ```bash kubectl taint node -l environment=production zone=node-2: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": "...
Create a copy of the 'payment-gateway-pod' pod with a debug container and changing the container images to 'debian'
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=my-debugger --image=debian --set-image=mailer=mailer:latest,web=nginx:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resour...
Forward local port 9090 to port 5000 in the 'api-service-pod' pod.
Command: ```bash kubectl port-forward pod/api-service-pod 9090: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...
Create a cluster role named "custom_role" with the ability to watch and access specific resources with resource names specified.
Command: ```bash kubectl create clusterrole custom_role --verb=watch --resource=pods --resource-name=mail-server --resource-name=nginx-proxy ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|n...
Forward traffic from all addresses on port 8000 to port 9090 in the pod named 'cdn-service-pod'
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 8000: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 w...
Create a new ExternalName service named external-analytics-service with the external name "dummy-website.io"
Command: ```bash kubectl create service externalname external-analytics-service --external-name dummy-website.io ``` 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 s...
Partially update the node "node-1" by applying the specified strategic merge patch in JSON format
Command: ```bash kubectl patch node node-1 -p '{"spec":{"rules":[{"http":{"paths":[{"path":"/","backend":{"service": {"name": "new-service"}}}]}}' ``` 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 ...
Update pod 'security' with the annotation 'SLA' and the value '99.9% uptime'
Command: ```bash kubectl annotate pods security SLA='99.9% uptime' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitrary ...
create a service for a replication controller identified by type and name specified in "hazelcast-controller.yaml"
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=9000 --target-port=900000 ``` 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 ...
Execute the 'geth version' command inside the first container of the first pod in the 'gateway-service' service.
Command: ```bash kubectl exec svc/gateway-service -- geth version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ...
Forward traffic from local port 8000 to port 6379 in the analytics-pod pod.
Command: ```bash kubectl port-forward pod/analytics-pod 8000: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 auto...
Update the environment variables of the 'email-server-deployment' deployment by importing the specific keys 'SMTP_SERVER' from the 'namespace-config' config map.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/namespace-config deployment/email-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 defi...
Set the service account of the load-balancer-deployment deployment to spinnaker
Command: ```bash kubectl set serviceaccount deployment load-balancer-deployment spinnaker ``` 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: `ku...
Forward local port 8080 to port 8888 in the pod "cdn-service-pod"
Command: ```bash kubectl port-forward pod/cdn-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 pod will be selected au...
Create a deployment named 'logging' with the 'node' image and expose port 3001
Command: ```bash kubectl create deployment logging --image=node --port=3001 ``` 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...
Listen on port 8000 on localhost (127.0.0.1) and IP 10.19.21.23, and forward the traffic to port 8080 in the pod named 'security-service-pod'.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-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 th...
Add a taint to the node 'edge-node-10' with the key 'hardware' and no value.
Command: ```bash kubectl taint nodes edge-node-10 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:...
Create a deployment named "web" using the "ethereum/client-go" image and expose port 8080
Command: ```bash kubectl create deployment web --image=ethereum/client-go --port=8080 ``` 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. ...
Update the image of all containers in the daemonset 'staging' to 'httpd:2.4.48'
Command: ```bash kubectl set image daemonset staging *=httpd:2.4.48 ``` 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: `kub...
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/db-config 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 variabl...
Create a role binding named "default_role" that grants the "default_role" cluster role to the users "jane.doe" and "bob.smith", as well as the "developers" group.
Command: ```bash kubectl create rolebinding default_role --clusterrole=default_role --user=jane.doe --user=bob.smith --group=developers ``` What it does: Create a role binding for a particular role or cluster role. Syntax: `kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--group=grou...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/monitoring-config deployment/load-balancer-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 variab...
Create a cluster role named "custom_role" with specific permissions and resource names
Command: ```bash kubectl create clusterrole custom_role --verb=get --resource=services --resource-name=auth-proxy --resource-name=billing-service ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cli...
Start streaming the logs of the stardust-shuttle container in the frontend-pod pod
Command: ```bash kubectl logs -f -c stardust-shuttle frontend-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",...
Start a pod named 'hazelcast' using the 'amazonlinux' image and expose port 5000 on the container
Command: ```bash kubectl run hazelcast --image=amazonlinux --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":...
Copy the ~/.config/kube local file to the /tmp/bar directory in the remote pod "message-broker-pod-15" in the kubeapps namespace.
Command: ```bash kubectl cp ~/.config/kube kubeapps/message-broker-pod-15::/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 ...
Delete resources from a directory using kustomization.yaml
Command: ```bash kubectl delete -k parameters/ ``` 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 resourc...
Auto scale the deployment "backend" with the number of pods between 6 and 10.
Command: ```bash kubectl autoscale deployment backend --min=6 --max=10 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses...
Create a new config map named monitoring-config from the key=value pairs in the file located at path/to/properties
Command: ```bash kubectl create configmap monitoring-config --from-file=path/to/properties ``` 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 b...
Forward port 8888 on localhost and IP address 10.19.21.23, to port 3000 in the e-commerce-pod container
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 8888: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 crit...
Set the environment variables that start with 'RAILS_' on the local shell to the 'frontend-deployment' deployment configuration on the server
Command: ```bash env | grep RAILS_ | kubectl set env -e - deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templ...
Create a service for the replication controller specified in "python-controller.yaml", serving on port 8084 and connecting to the containers on port 844300.
Command: ```bash kubectl expose -f python-controller.yaml --port=8084 --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...
Forward local port 3000 to port 8081 in the pod "analytics-pod" to listen on and forward data
Command: ```bash kubectl port-forward pod/analytics-pod 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 will be selected auto...
Forward traffic from port 6379 on localhost and IP 10.19.21.23 to port 8081 in the log-aggregator-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 6379: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 ...
Get output from running 'geth' command on the first pod of the load-balancer-deployment.
Command: ```bash kubectl exec deploy/load-balancer-deployment -- geth ``` 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 ...
Copy the file "/tmp/foo" from your local machine to the "/tmp/bar" directory in the "payment-gateway-pod-19" pod running on the "kube-server" server in the specified namespace.
Command: ```bash kubectl cp /tmp/foo kube-server/payment-gateway-pod-19:/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...
Forward traffic from local port 8000 to port 8088 in the pod
Command: ```bash kubectl port-forward pod/backend-pod 8000 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 automa...
Create a pod named 'hazelcast' with the 'mysql' image and expose port 8080
Command: ```bash kubectl run hazelcast --image=mysql --port=8080 ``` 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 specific keys from the "log-config" ConfigMap into the environment variables of the "order-processing-deployment" deployment
Command: ```bash kubectl set env --keys=config_file_path --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 d...
Create a copy of the 'media-stream-pod' pod, changing all container images to 'jenkins' and name the new pod 'my-debugger'
Command: ```bash kubectl debug media-stream-pod --copy-to=my-debugger --set-image=*=jenkins ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no re...
Remove an environment variable from a deployment and update the deployment configuration on the server
Command: ```bash kubectl set env -f deploy.json ENV- ``` 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 replication controllers...
Forward traffic from port 8081 on localhost and IP 10.19.21.23 to port 8888 in the pod named mypod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8081: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 p...
Set the client-key-data field in the robot-user user to the provided cert_data_here using the --set-raw-bytes=true option
Command: ```bash kubectl config set users.robot-user.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...
Create a new ClusterIP service named frontend-service-clusterip with target port 8888 and port 8088
Command: ```bash kubectl create service clusterip frontend-service-clusterip --tcp=8088:8888 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o...
Forward local ports 8081 and 6000 to ports 8000 and 6000 in a specific pod selected by the deployment
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 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 po...
Update the 'monitoring' pod by adding the label 'tier=frontend'
Command: ```bash kubectl label pods monitoring tier=frontend ``` 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...
Add a taint to a specific node with the specified key, value, and effect
Command: ```bash kubectl taint nodes web-node-8 hardware=gpu:NoExecute ``` 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...
List all replication controllers and services together in the ps output format.
Command: ```bash kubectl get rc,services ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only see results in your ...
Set the cluster field in the 'my-context' context to 'testing-cluster'.
Command: ```bash kubectl config set contexts.app-1-context.cluster testing-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you...
Add a taint with the key 'cpu-type' and value 'prod-node-5:PreferNoSchedule' on nodes that have the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha cpu-type=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": "", "u...
Update the 'chat-app' pod by adding an annotation 'contact-email' with the value 'support@example.com', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods chat-app contact-email='support@example.com' ``` 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 ...
Create an ingress named 'app2-ingress' that routes requests from foo.com/input to svc1:8089 using the TLS secret "my-cert".
Command: ```bash kubectl create ingress app2-ingress --rule="foo.com/input=svc1:8089,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": "...
Set custom TLS server name for e2e cluster
Command: ```bash kubectl config set-cluster e2e --tls-server-name=edge-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-authorit...
Create a new NodePort service named e-commerce-nodeport with the TCP port mapping 5000:9090.
Command: ```bash kubectl create service nodeport e-commerce-nodeport --tcp=5000:9090 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": ...
Output the modified payment-processor-deployment in YAML format by setting the environment variable ENV to "prod", without making any changes to the object on the server.
Command: ```bash kubectl set env deployment/payment-processor-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 temp...
Get the output from running the 'wp' command in warp-drive container of the monitoring-pod
Command: ```bash kubectl exec monitoring-pod -c warp-drive -- 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 k...
Create a copy of a pod called proxy-service-pod by adding a debug container and changing the container images to debian
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=debug-image-app --image=debian --set-image=api=api:v2,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...
Retrieve the logs from container database-deployment-1 of deployment proxy-service-pod
Command: ```bash kubectl logs deployment/database-deployment -c proxy-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: "fla...
Create a new config map named 'ui-config' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap ui-config --from-file=properties=/path/to/settings/file1.txt --from-file=key1=/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...
Begin streaming logs of a specific container in a pod
Command: ```bash kubectl logs -f -c quantum-quark frontend-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...
Forward port 9090 locally to the targetPort of the "https" port in a selected pod from the "logging-service" service
Command: ```bash kubectl port-forward service/logging-service 9090:https ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Create a secret named ldap-credentials-secret from the contents of a folder named "bar"
Command: ```bash kubectl create secret generic ldap-credentials-secret --from-file=path/to/settings ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the base...
Import environment variables prefixed with "MYSQL_" from a config map for a specific deployment.
Command: ```bash kubectl set env --from=configmap/app-config --prefix=MYSQL_ deployment/mydeployment ``` 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...
Port forward local port 8000 to pod port 5000
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 8000 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, ...
Display the resource usage metrics for all pods in the external-messaging-service namespace.
Command: ```bash kubectl top pod --namespace=external-messaging-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: `kub...
Forward traffic from local port 3000 to port 8000 in a pod selected by the deployment "monitoring-stack-deployment".
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 3000 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 ...
List all configmaps with additional information
Command: ```bash kubectl get configmaps -o wide ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only see results i...
Update the pod 'auth' by adding a label 'role' with the value 'cache'
Command: ```bash kubectl label pods auth role=cache ``` 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 tr...
Create a copy of the frontend pod with all container images changed to `ethereum/client-go`
Command: ```bash kubectl debug frontend-pod --copy-to=my-custom-dbg --set-image=*=ethereum/client-go ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default...
Create a job using the golang image that runs the hello.go command
Command: ```bash kubectl create job scaling-job --image=golang -- go run hello.go ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output form...
Autoscale the deployment named "foo" with a minimum of 4 pods and a maximum of 11 pods.
Command: ```bash kubectl autoscale deployment foo --min=4 --max=11 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Forward traffic from port 8088 on all addresses to port 8000 in the pod named "frontend-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 8088: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...
Create an ingress rule named 'web-ingress' that routes requests for 'website.com/example' to 'svc1:9091' with a TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress web-ingress --rule="website.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": "", "usag...
import the "max_connections" key from the "global-config" config map and set it as an environment variable in the "scheduler-app-deployment" deployment
Command: ```bash kubectl set env --keys=max_connections --from=configmap/global-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 de...
Create a job named "database-seeding-job" with the image "postgres" and run the command "postgres" inside the job.
Command: ```bash kubectl create job database-seeding-job --image=postgres -- postgres ``` 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 ...
Create a cluster role named "admin_role" with the ability to delete configmaps and specifically the resource names "api-server" and "load-balancer".
Command: ```bash kubectl create clusterrole admin_role --verb=delete --resource=configmaps --resource-name=api-server --resource-name=load-balancer ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|c...