prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Access the raw terminal mode of a pod and attach to it
Command: ```bash kubectl attach frontend-pod -c stardust-shuttle -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 o...
Create a deployment named 'web' using the 'amazonlinux' image and expose port 8080.
Command: ```bash kubectl create deployment web --image=amazonlinux --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. One of:...
Create a new ClusterIP service named 'order-service-clusterip' with the TCP port mapping from local port 8000 to container port 8082.
Command: ```bash kubectl create service clusterip order-service-clusterip --tcp=8000:8082 ``` 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 a new config map named 'app-config-dev' using the specified keys and file paths
Command: ```bash kubectl create configmap app-config-dev --from-file=conf=/path/to/properties/file1.txt --from-file=data=/path/to/profiles/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...
Import the 'MAX_CONNECTIONS' key from the 'app-settings' config map and set it as an environment variable in the 'notification-handler-deployment' deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-settings 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 varia...
Execute the 'go' command inside the first container of the first pod in the monitoring-service service.
Command: ```bash kubectl exec svc/monitoring-service -- 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 omitted, use the kubectl...
Create a cluster role named "custom_role" with the capability to update pods and with specific resource names "app-analytics" and "app-worker-1"
Command: ```bash kubectl create clusterrole custom_role --verb=update --resource=pods --resource-name=app-analytics --resource-name=app-worker-1 ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|clie...
Stream the logs of the nano-bot container in the chat-app-pod pod
Command: ```bash kubectl logs -f -c nano-bot chat-app-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short"...
Forward local port 8888 to port 3000 in the frontend-pod
Command: ```bash kubectl port-forward pod/frontend-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 criteria, a pod will be selected autom...
Remove the 'description' annotation from the 'web' pod
Command: ```bash kubectl annotate pods web description- ``` 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 string valu...
Set the service account of the deployment named 'notification-handler-deployment' to 'tiller'
Command: ```bash kubectl set serviceaccount deployment notification-handler-deployment tiller ``` 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:...
Import specific keys from a config map into the environment variables of a deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/log-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 i...
Delete pods and services named "monitoring" and "cdn"
Command: ```bash kubectl delete pod,service monitoring cdn ``` 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. ...
Display the resource metrics for the e-commerce-pod and its containers.
Command: ```bash kubectl top pod e-commerce-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 po...
import the "database_url" key from the config map and set it as an environment variable in the "cache-cluster-deployment" deployment
Command: ```bash kubectl set env --keys=database_url --from=configmap/env-vars 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 definition...
Execute the 'php --version' command in the quantum-quark container from the monitoring-pod pod.
Command: ```bash kubectl exec monitoring-pod -c quantum-quark -- 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 omit...
Create a copy of the backend-pod named my-debugger with a debug container inside
Command: ```bash kubectl debug backend-pod -it --copy-to=my-debugger --image=debian --set-image=worker=my-custom-worker:1.2.3,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identifie...
Start a mysql pod with the name nginx and the mysql image, while customizing the pod's spec using the values provided in the JSON format.
Command: ```bash kubectl run nginx --image=mysql --overrides='{ "apiVersion": "feature-branch-2.3.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] [--comman...
Port forward from local port 8080 to port 8088 in the backend pod
Command: ```bash kubectl port-forward pod/backend-pod 8080: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...
Delete resources from a directory using the `-k` flag and specifying the directory that contains the `kustomization.yaml` file.
Command: ```bash kubectl delete -k setup/ ``` 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 resources, s...
Copy a file from your local machine to a remote pod in a specified directory.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ openfaas/file-server-pod-14:/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": "...
Create an ingress called 'website-ingress' with a rule that directs requests from testing.com/bar to the service svc1:5000, and use the tls secret named "my-cert".
Command: ```bash kubectl create ingress website-ingress --rule="testing.com/bar=svc1:5000,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...
Execute the command 'pg_dump --version' inside the pod 'vpn-service-pod' and display the output.
Command: ```bash kubectl exec vpn-service-pod -- pg_dump --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...
Set the CPU and memory limits for the nginx container in the amazonlinux deployment
Command: ```bash kubectl set resources deployment amazonlinux -c=nginx --limits=cpu=5,memory=128Mi ``` 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...
Create a priority class named test-priority with a priority value of 20 and a description of "Priority for testing and validation"
Command: ```bash kubectl create priorityclass test-priority --value=20 --description="Priority for testing and validation" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=VALUE --global-default=BOOL [--dry-run=...
Import environment variables prefixed with "MYSQL_" from the config map named "ui-config" into the deployment "order-processing-deployment"
Command: ```bash kubectl set env --from=configmap/ui-config --prefix=MYSQL_ 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 definition...
Add a taint with the key 'cpu-type' on nodes having the label app=web-app
Command: ```bash kubectl taint node -l app=web-app cpu-type=k8s-node-1: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...
Return the previous terminated logs of the nano-bot container from the pod named "mypod".
Command: ```bash kubectl logs -p -c nano-bot mypod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c",...
Add a taint to the node 'kube-master-9' with the key 'zone' and no value
Command: ```bash kubectl taint nodes kube-master-9 zone:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: js...
Import the api_key key from the config map "ui-config" into the deployment "order-processing-deployment"
Command: ```bash kubectl set env --keys=api_key --from=configmap/ui-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 definitions...
Partially update the 'storage-node-13' node by setting the 'type' field to 'LoadBalancer' using a strategic merge patch specified as YAML
Command: ```bash kubectl patch node storage-node-13 -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]` Helpf...
List the deployments in the YAML output format for the "backup-apps" API group in the "rc-1.1.0" version.
Command: ```bash kubectl get deployments.rc-1.1.0.backup-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 w...
Start nginx pod with custom overrides
Command: ```bash kubectl run nginx --image=nginx --overrides='{ "apiVersion": "custom-version", "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] -- ...
Retrieve container logs from the web-app-deployment-1 container in the payment-gateway-pod deployment.
Command: ```bash kubectl logs deployment/web-app-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 flags: "fl...
View the last-applied-configuration annotations of the amazonlinux deployment in YAML format.
Command: ```bash kubectl apply view-last-applied deployment/amazonlinux ``` What it does: View the latest last-applied-configuration annotations by type/name or file. The default output will be printed to stdout in YAML format. You can use the -o option to change the output format. Syntax: `kubectl apply view-last-ap...
Expose a deployment as a service on port 5000, connecting to the containers on port 637900
Command: ```bash kubectl expose deployment hazelcast --port=5000 --target-port=637900 ``` 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 spec...
Create a deployment named "worker" using the "postgres" image and expose port 27017
Command: ```bash kubectl create deployment worker --image=postgres --port=27017 ``` 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...
Create a new ExternalName service named external-security-service that maps to the external DNS name documentation-tech.tech
Command: ```bash kubectl create service externalname external-security-service --external-name documentation-tech.tech ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to refer...
Copy the file "/tmp/foo" from the remote pod "kube-dns/api-server-pod-3" to the local directory "/tmp/bar"
Command: ```bash kubectl cp kube-dns/api-server-pod-3::/tmp/foo /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl...
Create an ingress called 'public-api-ingress' that directs requests to website.com/module to svc1:8082 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress public-api-ingress --rule="website.com/module=svc1:8082,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Execute a command inside a pod and retrieve the output
Command: ```bash kubectl exec analytics-pod -- /bin/bash -c "echo 'Hello, Amazon Linux'" ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container nam...
Forward data between local ports 5000 and 8081 to/from ports 8081 and 6000 in the pod named "backend-pod"
Command: ```bash kubectl port-forward pod/backend-pod 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 pod will be selected automa...
Add the 'compliance-level' annotation with the value 'PCI-DSS' to the 'proxy' pod.
Command: ```bash kubectl annotate pods proxy 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 arbitra...
List the specified resources by their type and names.
Command: ```bash kubectl get rc/web service/monitoring-rc pods/media-stream-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...
Copy the kube local file from your local machine to the /tmp/bar directory in the file-server container of the admin-dashboard-pod-16 pod.
Command: ```bash kubectl cp ~/.config/kube admin-dashboard-pod-16:/tmp/bar -c file-server ``` 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...
Start a hazelcast pod named nginx using the hazelcast/hazelcast image, but override the specifications with a partial set of values parsed from JSON.
Command: ```bash kubectl run nginx --image=hazelcast/hazelcast --overrides='{ "apiVersion": "legacy-1.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] [--...
Create a new NodePort service named 'e-commerce-nodeport' that maps port 8084 on the cluster to port 8010 on the target Pods.
Command: ```bash kubectl create service nodeport e-commerce-nodeport --tcp=8084:8010 ``` 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": ...
Forward data between the local ports 9090 and 6000 and the pod's ports 5000 and 6000 in the 'log-aggregator-pod'.
Command: ```bash kubectl port-forward pod/log-aggregator-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...
Create a new ClusterIP service named security-service-clusterip that maps port 7000 externally to port 27017 internally.
Command: ```bash kubectl create service clusterip security-service-clusterip --tcp=7000:27017 ``` 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": "-...
Execute the 'node' command inside the 'proxy-server-pod' pod, using the first container by default
Command: ```bash kubectl exec proxy-server-pod -- node ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kub...
Import environment variables from the 'ui-config' config map into the 'MYSQL_' prefix in the 'email-server-deployment' deployment
Command: ```bash kubectl set env --from=configmap/ui-config --prefix=MYSQL_ 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 definitions in...
Add a taint with the key 'zone' and the value 'prod-node-5:PreferNoSchedule' on nodes that have the label 'region=eu-west-2'
Command: ```bash kubectl taint node -l region=eu-west-2 zone=prod-node-5:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
List the deployments in the "feature-branch-2.3.0" version of the "apps" API group in JSON format.
Command: ```bash kubectl get deployments.feature-branch-2.3.0.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 ...
Copy the local file /tmp/foo to the remote pod security-scanner-pod-18 in namespace kube-node-lease, and place it at /tmp/bar
Command: ```bash kubectl cp /tmp/foo kube-node-lease/security-scanner-pod-18::/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, u...
Retrieve the logs of the previous terminated ruby container from the pod named "security-service-pod"
Command: ```bash kubectl logs -p -c ruby security-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "sh...
Return the snapshot logs from the container proxy-service-deployment-1 of the vpn-service-pod deployment.
Command: ```bash kubectl logs deployment/proxy-service-deployment -c vpn-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "...
Import the REDIS_HOST key from the config map called db-config into the scheduler-app-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/db-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 definitions...
Set the CPU limits of the nginx container in the deployment to "200m" and memory limits to "4Gi".
Command: ```bash kubectl set resources deployment nginx -c=nginx --limits=cpu=200m,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 i...
If the current size of the deployment named app-v2-replicaset is 3, scale the mysql deployment to 7.
Command: ```bash kubectl scale --current-replicas=3 --replicas=7 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...
Add a taint with the key 'cpu-type' on nodes having the label 'role=database'.
Command: ```bash kubectl taint node -l role=database cpu-type=web-node-8:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Forward local port 8080 to port 8888 in the security-service-pod pod
Command: ```bash kubectl port-forward pod/security-service-pod 8080 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Access the interactive Ruby (irb) console in the database-pod pod.
Command: ```bash kubectl exec database-pod -- 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 kubectl.kubernet...
Create a new config map named app-config-prod using specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-prod --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/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 cr...
Open a raw terminal session with the "lunar-launcher" container in the "proxy-service-pod" pod
Command: ```bash kubectl attach proxy-service-pod -c lunar-launcher -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. I...
Create a copy of the 'vpn-service-pod' pod, adding a debug container and changing the container images
Command: ```bash kubectl debug vpn-service-pod -it --copy-to=my-debugger --image=debian --set-image=web=nginx:latest,app=app:debug ``` 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...
Run the 'jenkins-plugin-cli' command in the lunar-launcher container of the proxy-service-pod pod and display the output
Command: ```bash kubectl exec proxy-service-pod -c lunar-launcher -- jenkins-plugin-cli ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name...
Create a service for a replication controller based on the specifications provided in the "wordpress-controller.yaml" file, which connects to the containers on port 8000 and serves on port 80
Command: ```bash kubectl expose -f wordpress-controller.yaml --port=3306 --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 ...
Update the annotation "git-repo" in the pod specified in "preferences.json" with the value "https://github.com/example/my-app"
Command: ```bash kubectl annotate -f preferences.json git-repo='https://github.com/example/my-app' ``` 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 th...
Create a debug copy of the web-app-pod by adding a debug container and changing container images
Command: ```bash kubectl debug web-app-pod -it --copy-to=debug-image-memcached --image=debian --set-image=scheduler=my-scheduler:1.0,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects...
Taint nodes with 'cpu-type' key on nodes having label team=devops
Command: ```bash kubectl taint node -l team=devops cpu-type=kube-master-9: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 service using the specifications in the 'hazelcast-controller.yaml' file
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=5432 --target-port=300000 ``` 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 ...
List the replication controller 'web', the service 'log-aggregator-rc', and the pod 'log-aggregator-pod'
Command: ```bash kubectl get rc/web service/log-aggregator-rc pods/log-aggregator-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 ...
display the replication controller with the name 'web', the service with the name 'log-aggregator-rc', and the pod with the name 'chat-app-pod'
Command: ```bash kubectl get rc/web service/log-aggregator-rc pods/chat-app-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namesp...
Import the API_KEY key from the 'app-settings' config map into the 'notification-handler-deployment' deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-settings deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Execute the 'python' command in the cosmic-container of the email-service-pod and get the output.
Command: ```bash kubectl exec email-service-pod -c cosmic-container -- 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 omitt...
Taint nodes with label 'stack=tech-stack' with a taint key 'workload' and a value 'db-node-7' that prevents scheduling of new pods unless explicitly tolerated.
Command: ```bash kubectl taint node -l stack=tech-stack workload=db-node-7:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Get the output from running the 'go' command in the chat-app-pod
Command: ```bash kubectl exec chat-app-pod -- 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 omitted, use the kubectl.kubernete...
Get the output of the 'jenkins --version' command from the first container in the 'media-stream-pod' pod
Command: ```bash kubectl exec media-stream-pod -- jenkins --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Import the 'database_url' key from the 'kube-system-config' config map into the 'gateway-deployment' deployment
Command: ```bash kubectl set env --keys=database_url --from=configmap/kube-system-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Retrieve the output from running the command 'kafka-console-producer --broker-list localhost:9092 --topic test' inside the first container of the 'notification-handler-deployment' deployment.
Command: ```bash kubectl exec deploy/notification-handler-deployment -- kafka-console-producer --broker-list localhost:9092 --topic test ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "shor...
Add a taint with key 'app' on nodes labeled with zone=us-east-1
Command: ```bash kubectl taint node -l zone=us-east-1 app=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Ou...
Use "gedit" as the editor to edit the "authentication-service" service
Command: ```bash KUBE_EDITOR="gedit" kubectl edit svc/authentication-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 v...
Create a deployment called logging that runs the wordpress image and exposes port 9090
Command: ```bash kubectl create deployment logging --image=wordpress --port=9090 ``` 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 o...
Update the image of all containers in the daemonset "namespace-1" to "ruby:3.0.2"
Command: ```bash kubectl set image daemonset namespace-1 *=ruby:3.0.2 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `k...
Create a service for a replicated node that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose rc node --port=8181 --target-port=909200 ``` 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. A...
Set the custom TLS server name to "testing-cluster" for the "dev-cluster" cluster entry.
Command: ```bash kubectl config set-cluster dev-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] [--certifica...
Create a single ingress called 'api-ingress' that directs requests to site.com/input to svc1:3000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress api-ingress --rule="site.com/input=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": "", "usage": "...
Output a modified deployment in YAML format without altering the object on the server
Command: ```bash kubectl set env deployment/email-server-deployment CACHE_SIZE=64MB -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 te...
Create an ingress called 'default-ingress' that routes requests from testing.com/example to the service 'svc1' on port 9000
Command: ```bash kubectl create ingress default-ingress --rule="testing.com/example=svc1:9000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/namespace-config 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 def...
Return the previous terminated logs from the 'mycontainer' container in the 'cdn-service-pod' pod
Command: ```bash kubectl logs -p -c mycontainer cdn-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "...
Add a taint with key 'environment' and value 'kube-master-9:PreferNoSchedule' on nodes having label 'owner=john-doe'
Command: ```bash kubectl taint node -l owner=john-doe environment=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Update the scaling policy of a pod defined in "setup.json" to enable auto-horizontal scaling.
Command: ```bash kubectl annotate -f setup.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 an...
Forward local ports 8080 to 8088 of the selected pod in the deployment "api-server-deployment"
Command: ```bash kubectl port-forward deployment/api-server-deployment 8080 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 b...
Update the 'user-management-deployment' deployment by adding a new environment variable JWT_SECRET with the value 'your-jwt-secret'.
Command: ```bash kubectl set env deployment/user-management-deployment JWT_SECRET=your-jwt-secret ``` 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 ...
Forward traffic from local port 5000 to port 5432 in the 'backend-pod' pod
Command: ```bash kubectl port-forward pod/backend-pod 5000 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Forward traffic from port 8088 on localhost and IP 10.19.21.23 to port 8080 in the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 8088: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 crit...
Create a new secret named azure-storage-secret with the keys key1=supersecret and key2=topsecret.
Command: ```bash kubectl create secret generic azure-storage-secret --from-literal=key1=supersecret --from-literal=key2=topsecret ``` 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, th...
Create a new config map named kube-system-config using the properties and key1 keys from the specified files.
Command: ```bash kubectl create configmap kube-system-config --from-file=properties=/path/to/configurations/file1.txt --from-file=key1=/path/to/parameters/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....
Forward local port 5432 to port 5432 in the pod named "analytics-pod" for listening
Command: ```bash kubectl port-forward pod/analytics-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 be selected auto...