prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Expose the replica set "ubuntu" as a service on port 3306, connecting to the containers on port 801000
Command: ```bash kubectl expose rs ubuntu --port=3306 --target-port=801000 ``` 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....
Update the expiration date of a pod specified in the "config.json" file.
Command: ```bash kubectl annotate -f config.json expiration-date='2024-12-31' ``` 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...
Return the snapshot logs from the container "email-service-pod-1" of the deployment "notification-handler-deployment"
Command: ```bash kubectl logs deployment/notification-handler-deployment -c email-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...
Forward local port 5432 to port 8000 in the pod named 'backend-pod'
Command: ```bash kubectl port-forward pod/backend-pod 5432:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Add a taint with key 'cpu-type' on nodes having label tier=frontend with the value 'dev-node-4' and the effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l tier=frontend cpu-type=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": "O...
List deployments in the "stable-2.0.0" version of the "api-v1" API group in JSON output format.
Command: ```bash kubectl get deployments.stable-2.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 wi...
rename a context in the kubeconfig file
Command: ```bash kubectl config rename-context local-context app-2-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 nginx image and expose port 3306
Command: ```bash kubectl run hazelcast --image=nginx --port=3306 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--fi...
List deployments in YAML format for the "stable-2.0.0" version of the "prod-apps" API group.
Command: ```bash kubectl get deployments.stable-2.0.0.prod-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...
Embed the certificate authority data for the "star-cluster" cluster entry by running the command "kubectl config set-cluster star-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-1/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster star-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-1/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...
Remove the context for the cluster-2-context cluster.
Command: ```bash kubectl config delete-context cluster-2-context ``` What it does: Delete the specified context from the kubeconfig. Syntax: `kubectl config delete-context NAME`
Create a new config map named app-settings based on the folder profiles
Command: ```bash kubectl create configmap app-settings --from-file=path/to/profiles ``` 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 basename...
Create a job named 'database-seeding-job' using the 'alpine' image with the command 'apk add curl'
Command: ```bash kubectl create job database-seeding-job --image=alpine -- apk add curl ``` 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": "Outpu...
Create a pod named hazelcast using the elasticsearch image. Expose port 8443 in the container.
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --port=8443 ``` 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] ...
Create a single ingress called 'public-service-ingress' with the following rules: requests to testing.com/bar should be directed to svc1:7000, and a tls secret named "my-cert" should be used.
Command: ```bash kubectl create ingress public-service-ingress --rule="testing.com/bar=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": ""...
Import specific keys from a config map into a deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/ui-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 variable definitions in...
Forward local traffic from port 5000 to port 8000 in the analytics-pod pod.
Command: ```bash kubectl port-forward pod/analytics-pod 5000 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected auto...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/global-config deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Change the cluster field in the 'local-context' context to 'star-cluster'
Command: ```bash kubectl config set contexts.local-context.cluster star-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 wa...
Create a new config map named app-settings using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-settings --from-file=settings=/path/to/data/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 creating a conf...
Import environment variables from the 'monitoring-credentials-secret' secret into the 'monitoring-stack-deployment' deployment.
Command: ```bash kubectl set env --from=secret/monitoring-credentials-secret deployment/monitoring-stack-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 definitio...
Update the environment variables of a deployment with specific keys from a config map.
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-name-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 varia...
Forward local port 5000 to port 8000 in the pod "e-commerce-pod"
Command: ```bash kubectl port-forward pod/e-commerce-pod 5000:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Get the output from the astro-container in the api-service-pod pod.
Command: ```bash kubectl attach api-service-pod -c astro-container ``` 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 omitt...
Import environment variables from a secret to a deployment.
Command: ```bash kubectl set env --from=secret/cert-manager-secret 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 more pod tem...
Add a taint with the key 'app' and the value 'backup-node-14:PreferNoSchedule' on all nodes in the cluster labeled as 'cluster=my-cluster'
Command: ```bash kubectl taint node -l cluster=my-cluster app=backup-node-14: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 new config map named global-config and populate it with values from specified files
Command: ```bash kubectl create configmap global-config --from-file=settings=/path/to/parameters/file1.txt --from-file=key2=/path/to/data/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a ...
Create a new config map named "monitoring-config" using the files "file1.txt" and "file2.txt" as values for keys "settings" and "key2" respectively.
Command: ```bash kubectl create configmap monitoring-config --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/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 ...
Forward local port 5432 to pod port 8888 of the frontend-pod
Command: ```bash kubectl port-forward pod/frontend-pod 5432 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 autom...
Attach to the cyber-sleuth container in the web-app-pod pod, switch to raw terminal mode, and send stdin to 'bash' in the cyber-sleuth container
Command: ```bash kubectl attach web-app-pod -c cyber-sleuth -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 omitte...
Create a copy of the gateway-pod, adding a debug container and changing the container images
Command: ```bash kubectl debug gateway-pod -it --copy-to=my-custom-dbg --image=debian --set-image=proxy=nginx:1.21,api=api:v2 ``` 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. Pod...
Specify the keys to import from a config map into a deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-name-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 var...
Import the 'max_connections' key from the 'db-config' config map and set it as an environment variable for the 'gateway-deployment' deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/db-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 definitions ...
Update the node 'app-node-6' by adding a taint with the key 'dedicated', value 'special-user', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes app-node-6 dedicated=special-user: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 for...
Return the logs of the previous terminated "time-machine" container in the "backend-pod" pod.
Command: ```bash kubectl logs -p -c time-machine backend-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", "sho...
Copy the file "/tmp/foo" from the remote pod "kube-flannel/metrics-exporter-pod-10" to the local path "/etc/kubernetes".
Command: ```bash kubectl cp kube-flannel/metrics-exporter-pod-10::/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 omitte...
List the resources of specific types and names.
Command: ```bash kubectl get rc/web service/web-app-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 namespa...
Create a job named "monitoring-job" using the nginx image. The job will run the command "nginx -g 'daemon off;'"
Command: ```bash kubectl create job monitoring-job --image=nginx -- nginx -g "daemon off;" ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Ou...
create a job named testing with the python image, executing the command "pip --version"
Command: ```bash kubectl create job testing --image=python -- pip --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 format. On...
Taint the nodes with the label "owner=john-doe" by adding a taint with the key "dedicated" and value "dev-node-4:PreferNoSchedule"
Command: ```bash kubectl taint node -l owner=john-doe dedicated=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": ...
Auto scale the deployment "gateway" with a minimum of 4 pods and a maximum of 10 pods.
Command: ```bash kubectl autoscale deployment gateway --min=4 --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...
Configure auto scaling for the replication controller "auth" with a target CPU utilization of 50% and a minimum of 1 pod and a maximum of 6 pods.
Command: ```bash kubectl autoscale rc auth --max=6 --cpu-percent=50 ``` 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 th...
Rename the context 'staging-context' to 'user-b-context' in your kubeconfig file.
Command: ```bash kubectl config rename-context staging-context user-b-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 al...
Set resource request and limits for all containers in a python deployment
Command: ```bash kubectl set resources deployment python --limits=cpu=200m,memory=512Mi --requests=cpu=50m,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 reques...
Start a php pod with custom specifications provided in a JSON format
Command: ```bash kubectl run nginx --image=php --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] -- [COMMAND] ...
Forward the local port 6379 to the pod's port 5432 for the 'log-aggregator-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 6379: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 ...
Forward local port 8080 to port 8080 in the security-service-pod
Command: ```bash kubectl port-forward pod/security-service-pod 8080 8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Create a job named security-scan-job using the busybox image.
Command: ```bash kubectl create job security-scan-job --image=busybox ``` 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 format. One of: ...
Copy the file "/tmp/foo" from the remote pod named "rook-ceph/security-scanner-pod-18" to the local directory "/tmp/bar".
Command: ```bash kubectl cp rook-ceph/security-scanner-pod-18::/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...
Start a Jenkins pod named 'hazelcast' using the Jenkins image, and configure the container to expose port 8443.
Command: ```bash kubectl run hazelcast --image=jenkins --port=8443 ``` 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": "--...
Update the last-applied-configuration of a resource using the contents of the 'pod.yaml' file
Command: ```bash kubectl apply set-last-applied -f pod.yaml ``` What it does: Set the latest last-applied-configuration annotations by setting it to match the contents of a file. This results in the last-applied-configuration being updated as though 'kubectl apply -f ' was run, without updating any other parts of the ...
Run the 'postgres' command in the 'warp-drive' container of the 'gateway-pod' pod and display the output
Command: ```bash kubectl exec gateway-pod -c warp-drive -- postgres ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Create a deployment named grafana running the wordpress image and exposing port 9091
Command: ```bash kubectl create deployment grafana --image=wordpress --port=9091 ``` 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...
Import the REDIS_HOST key from the api-config ConfigMap and set it as an environment variable in the user-management-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/api-config deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definiti...
Create a role binding named "reader" with the "reader" cluster role, assigning it to the "admin" user, "devops-user" user, and "operations-team" group.
Command: ```bash kubectl create rolebinding reader --clusterrole=reader --user=admin --user=devops-user --group=operations-team ``` 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=groupname] [...
Return the previous logs of the terminated stardust-shuttle container from the frontend-pod
Command: ```bash kubectl logs -p -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",...
Create a new config map named kube-system-config with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap kube-system-config --from-file=properties=/path/to/profiles/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 cre...
Create a job named scaling-job using the dotnet/core/runtime image. The job should run the 'dotnet' command.
Command: ```bash kubectl create job scaling-job --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet ``` 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": "",...
Edit the last-applied-configuration annotations of a deployment named "wordpress"
Command: ```bash kubectl apply edit-last-applied deployment/wordpress ``` What it does: Edit the latest last-applied-configuration annotations of resources from the default editor. The edit-last-applied command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the e...
Create a deployment named "grafana" using the "golang" image and expose port 27017.
Command: ```bash kubectl create deployment grafana --image=golang --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:...
Import the environment variables from the ssh-key-secret secret into the web-app-deployment deployment
Command: ```bash kubectl set env --from=secret/ssh-key-secret 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 definitions in one or more pod te...
Scale the deployment named bar to 1 replica
Command: ```bash kubectl scale --current-replicas=3 --replicas=1 deployment/bar ``` 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...
Create a cron job called log-rotation with the image mysql, which will run the command mysqld every minute.
Command: ```bash kubectl create cronjob log-rotation --image=mysql --schedule="*/1 * * * *" -- mysqld ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "def...
Create a service for the replicated python using a replica set, which will be served on port 5432 and connect to the containers on port 909200.
Command: ```bash kubectl expose rs python --port=5432 --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....
Create a single ingress called 'app-loadbalancer-ingress' that directs requests to foo.com/module to svc1:8443 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="foo.com/module=svc1:8443,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": "...
Return the snapshot logs from the container named database-deployment-1 of the deployment named frontend-pod.
Command: ```bash kubectl logs deployment/database-deployment -c frontend-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "...
Create a secret named my-secret using the values from the specified env file
Command: ```bash kubectl create secret generic my-secret --from-env-file=path/to/parameters.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basename...
Drain the "monitoring-node-15" node, including the pods that are not managed by any controller, by using the "kubectl drain" command with the "--force" flag.
Command: ```bash kubectl drain monitoring-node-15 --force ``` What it does: Drain node in preparation for maintenance. The given node will be marked unschedulable to prevent new pods from arriving. 'drain' evicts the pods if the API server supports https://kubernetes.io/docs/concepts/workloads/pods/disruptions/ . Othe...
Create a new config map with the name "db-config" and populate it with key-value pairs based on files located at "/path/to/configs/file1.txt" and "/path/to/configurations/file2.txt" respectively.
Command: ```bash kubectl create configmap db-config --from-file=conf=/path/to/configs/file1.txt --from-file=data=/path/to/configurations/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...
Update the environment variable 'SECRET_KEY' for the deployment 'frontend-deployment' with the value 'your-secret-key'
Command: ```bash kubectl set env deployment/frontend-deployment SECRET_KEY=your-secret-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 more pod tem...
Retrieve the snapshot logs from the container "authentication-service-deployment-1" of the deployment named "log-aggregator-pod".
Command: ```bash kubectl logs deployment/authentication-service-deployment -c log-aggregator-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]` Help...
Update the pod identified by type and name in "setup.json" and add an annotation with the value "Prometheus" for the key "monitoring-tool"
Command: ```bash kubectl annotate -f setup.json monitoring-tool=Prometheus ``` 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 ar...
Create a job named "cleanup" with the image "node" and run the command "npm --version"
Command: ```bash kubectl create job cleanup --image=node -- npm --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 format. One ...
Set the custom TLS server name for the specified cluster entry.
Command: ```bash kubectl config set-cluster my-k8s-cluster --tls-server-name=e2e ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-author...
Copy the local file /tmp/foo_dir to the remote pod kubeapps/payment-gateway-pod-19 in the /tmp/bar_dir directory
Command: ```bash kubectl cp /tmp/foo_dir kubeapps/payment-gateway-pod-19:/tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Taint nodes with label 'myLabel' by adding the taint 'datacenter=app-node-6:PreferNoSchedule'
Command: ```bash kubectl taint node -l myLabel datacenter=app-node-6:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outpu...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/env-vars deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Set resource request and limits for all containers in the "mongo" deployment
Command: ```bash kubectl set resources deployment mongo --limits=cpu=200m,memory=512Mi --requests=cpu=10,memory=64Mi ``` 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...
Forward local port 3000 to port 9090 in the pod named api-service-pod.
Command: ```bash kubectl port-forward pod/api-service-pod 3000: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 au...
Create a copy of the 'proxy-server-pod' and change all container images to 'ruby'
Command: ```bash kubectl debug proxy-server-pod --copy-to=my-custom-dbg --set-image=*=ruby ``` 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...
Set the environment variables that start with "RAILS_" in your local shell environment into the "user-management-deployment" on the server.
Command: ```bash env | grep RAILS_ | kubectl set env -e - deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more po...
Get the output from running the 'nginx' command in the proxy-server-pod container
Command: ```bash kubectl exec proxy-server-pod -- nginx ``` 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.ku...
List the deployments in the "v2.0.0" version of the "api-v1" API group in JSON output format.
Command: ```bash kubectl get deployments.v2.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...
Import environment variables from a secret to a deployment
Command: ```bash kubectl set env --from=secret/ssh-key-secret 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 definitions in one or more pod te...
Describe pods with label component=proxy
Command: ```bash kubectl describe po -l component=proxy ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type, provi...
Forward local port 5000 to port 6379 in the pod named "mypod"
Command: ```bash kubectl port-forward pod/mypod 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 automaticall...
Create a job named 'security-scan-job' using the 'python' image and execute the command 'pip --version'
Command: ```bash kubectl create job security-scan-job --image=python -- pip --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 ...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-config-prod 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 d...
Set environment variables from specific keys in a config map.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-secrets 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 ...
Execute the 'mongod' command in the 'warp-drive' container of the 'frontend-pod' pod.
Command: ```bash kubectl exec frontend-pod -c warp-drive -- mongod ``` 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...
Run the 'redis-server --version' command in the code-explorer container of the media-stream-pod and get the output
Command: ```bash kubectl exec media-stream-pod -c code-explorer -- redis-server --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 na...
Create a new config map named monitoring-config using data from specific files
Command: ```bash kubectl create configmap monitoring-config --from-file=conf=/path/to/data/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 co...
Set the resource request and limits for all containers in the postgres deployment to a CPU limit of 200 milliCPU and memory limit of 512Mi, and a CPU request of 100 milliCPU and memory request of 128Mi.
Command: ```bash kubectl set resources deployment postgres --limits=cpu=200m,memory=512Mi --requests=cpu=100m,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 req...
Create a job with a cleanup command
Command: ```bash kubectl create job cleanup --image=ruby -- irb ``` 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 format. One of: json|y...
Create an ingress named 'app-proxy-ingress' that directs requests for testing.com/example to svc1 on port 8082, and use the tls secret 'my-cert'.
Command: ```bash kubectl create ingress app-proxy-ingress --rule="testing.com/example=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": "",...
Forward all incoming traffic on port 6379 to port 5432 in the log-aggregator-pod, and listen on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 6379: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 po...
Listen on port 8081 on localhost and IP address 10.19.21.23, and forward the traffic to port 5432 in the 'frontend-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 8081: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 criter...
Update the deployment 'analytics-platform-deployment' by setting a new environment variable called 'LOG_LEVEL' to the value 'info'
Command: ```bash kubectl set env deployment/analytics-platform-deployment LOG_LEVEL=info ``` 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...
Retrieve the logs from container search-engine-deployment-1 in the cdn-service-pod deployment.
Command: ```bash kubectl logs deployment/search-engine-deployment -c cdn-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "...
Set the service account of the deployment cache-cluster-deployment to istio.
Command: ```bash kubectl set serviceaccount deployment cache-cluster-deployment istio ``` 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: `kubect...