prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Set the CPU limit to 200m and memory limit to 512Mi, and set the CPU request to 2 and memory request to 1Gi for all containers in the kafka deployment.
Command: ```bash kubectl set resources deployment kafka --limits=cpu=200m,memory=512Mi --requests=cpu=2,memory=1Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, ...
Start an nginx pod and expose port 8080 on the container
Command: ```bash kubectl run hazelcast --image=nginx --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...
Create a LoadBalancer service named frontend-lb to load balance traffic on port 8081 to port 8089
Command: ```bash kubectl create service loadbalancer frontend-lb --tcp=8089:8081 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "defaul...
Start a pod named 'hazelcast' with the 'node' image and expose port 8081
Command: ```bash kubectl run hazelcast --image=node --port=8081 ``` 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": "--fil...
Create a new config map named 'db-config' with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap db-config --from-file=settings=/path/to/settings/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 config...
remove both the 'analytics' pod and service, as well as the 'log-aggregator' pod and service
Command: ```bash kubectl delete pod,service analytics log-aggregator ``` 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 ...
Copy the local file ~/.config/kube to the remote pod backend-pod-13 in the kube-public namespace
Command: ```bash kubectl cp ~/.config/kube kube-public/backend-pod-13:/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the k...
Execute the 'jenkins-plugin-cli' command in the 'cosmic-container' from the pod named 'email-service-pod'
Command: ```bash kubectl exec email-service-pod -c cosmic-container -- 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 na...
Add a taint with key 'dedicated' on nodes having label 'service=auth'
Command: ```bash kubectl taint node -l service=auth dedicated=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": "Outpu...
Forward port 6379 on your local machine to port 8080 in the proxy-server-pod pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 6379:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Retrieve the logs of the previous terminated time-machine container from the pod named proxy-service-pod
Command: ```bash kubectl logs -p -c time-machine proxy-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"...
Setup autoscaling for the "analytics" deployment with a minimum of 5 pods and a maximum of 13 pods
Command: ```bash kubectl autoscale deployment analytics --min=5 --max=13 ``` 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 us...
Create a LoadBalancer service named 'vpn-service-lb' that maps port 8088 to port 8443
Command: ```bash kubectl create service loadbalancer vpn-service-lb --tcp=8088:8443 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "def...
Add a taint with key 'dedicated' on nodes having label instance=app-instance-1
Command: ```bash kubectl taint node -l instance=app-instance-1 dedicated=gpu-node-12: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": "",...
Auto scale the replication controller "api" with a target CPU utilization of 20%, allowing the number of pods to range between 1 and 4.
Command: ```bash kubectl autoscale rc api --max=4 --cpu-percent=20 ``` 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...
create a service for the replicated python deployment that serves on port 8088 and connects to the containers on port 808400
Command: ```bash kubectl expose rc python --port=8088 --target-port=808400 ``` 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....
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/db-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...
Access the running pod named 'security-service-pod' and execute the 'ash' command in the 'lunar-launcher' container to get the output.
Command: ```bash kubectl exec security-service-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...
Copy the ~/.config/kube local file to :/tmp/bar in the remote pod "logging-agent-pod-7" in the "kube-dns" namespace.
Command: ```bash kubectl cp ~/.config/kube kube-dns/logging-agent-pod-7::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Forward local port to pod port
Command: ```bash kubectl port-forward pod/mypod 5432: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 automaticall...
Execute the 'elasticsearch' command in the 'cyber-sleuth' container of the 'frontend-pod' pod and display the output.
Command: ```bash kubectl exec frontend-pod -c cyber-sleuth -- elasticsearch ``` 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...
Apply a taint to the 'dev-node-4' node with the key 'workload', value 'high-priority', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes dev-node-4 workload=high-priority: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...
create a new config map named 'api-config' and set the values 'config1' and 'config2' for the keys 'key1' and 'key2' respectively
Command: ```bash kubectl create configmap api-config --from-literal=conf=config1 --from-literal=data=config2 ``` 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 wil...
Set the custom TLS server name 'on-prem-cluster' for the 'cluster-beta' cluster entry.
Command: ```bash kubectl config set-cluster cluster-beta --tls-server-name=on-prem-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certific...
Forward port 8888 on all addresses to port 9090 in the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 8888: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 po...
Create a service for the replication controller specified in the "ruby-controller.yaml" file, exposing port 80 and connecting to the containers on port 8000.
Command: ```bash kubectl expose -f ruby-controller.yaml --port=9092 --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 s...
Copy the file /tmp/foo from a remote pod to /tmp/bar locally.
Command: ```bash kubectl exec -n cert-manager monitoring-agent-pod-6 -- tar cf - /tmp/foo | tar xf - -C /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": "Con...
Update the annotation 'expiration-date' of pod 'foo' to '2024-12-31', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods foo 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 i...
Import environment variables from the config map "app-config" with the prefix "MYSQL_" into the "user-management-deployment" deployment.
Command: ```bash kubectl set env --from=configmap/app-config --prefix=MYSQL_ 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 definition...
List all supported API resources with additional information
Command: ```bash kubectl api-resources -o wide ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Create a debug container named "debug-image-api" from the "payment-gateway-pod" pod, and replace all container images with "ethereum/client-go".
Command: ```bash kubectl debug payment-gateway-pod --copy-to=debug-image-api --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 b...
Create a secret named monitoring-credentials-secret with key1 and key2 as literal values
Command: ```bash kubectl create secret generic monitoring-credentials-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...
Forward port 6379 locally to port 8000 in the pod named "mypod"
Command: ```bash kubectl port-forward pod/mypod 6379: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 automaticall...
Create a pod disruption budget named 'payment-gateway-pdb' that will select all pods with the 'owner=team-1' label and require a minimum of four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget payment-gateway-pdb --selector=owner=team-1 --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available...
Update the pod 'cdn' by setting the annotation 'expiration-date' to '2024-12-31', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods cdn 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 i...
Autoscale the "vpn" deployment with a minimum of 1 pod and a maximum of 11 pods, using the default autoscaling policy.
Command: ```bash kubectl autoscale deployment vpn --min=1 --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...
Create a job named 'data-migration-job' using the 'alpine' image, and run the command 'sleep 3600' inside the job
Command: ```bash kubectl create job data-migration-job --image=alpine -- sleep 3600 ``` 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 fo...
Get the output from the stardust-shuttle container in the payment-gateway-pod
Command: ```bash kubectl attach payment-gateway-pod -c stardust-shuttle ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If ...
Execute the command '/bin/bash -c "echo 'Hello, Amazon Linux'"' inside the first container of the first pod of the frontend-service service and display the output.
Command: ```bash kubectl exec svc/frontend-service -- /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": "Contai...
Taint the nodes labeled as 'cluster=my-cluster' by adding a taint with the key 'zone' and value 'app-node-6' with effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l cluster=my-cluster zone=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": "...
Create an ingress resource called 'default-ingress' with a rule that directs requests to 'website.com/input' to the service named 'svc1' on port 8181
Command: ```bash kubectl create ingress default-ingress --rule="website.com/input=svc1:8181,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Auto scale the replication controller "security" with a target CPU utilization of 90% and a maximum of 3 pods.
Command: ```bash kubectl autoscale rc security --max=3 --cpu-percent=90 ``` 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 use...
Update the annotation of pod 'web' with the value 'Prometheus' for the key 'monitoring-tool', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods web 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 i...
Create a new config map named "app-name-config" with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-name-config --from-file=properties=/path/to/properties/file1.txt --from-file=key1=/path/to/properties/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 c...
Embed the certificate authority data for the "prod-cluster" cluster entry.
Command: ```bash kubectl config set-cluster prod-cluster --embed-certs --certificate-authority=~/.kube/galaxy-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config s...
Import the LOG_LEVEL key from the app-settings config map and set it as an environment variable for the log-aggregator-deployment deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-settings 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 definiti...
Update the image of all containers in the 'namespace-3' daemonset to 'ruby:3.0.2'
Command: ```bash kubectl set image daemonset namespace-3 *=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...
Set the server field to 'https://1.2.3.4' on the my-k8s-cluster cluster.
Command: ```bash kubectl config set clusters.my-k8s-cluster.server https://1.2.3.4 ``` 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...
Create a new ExternalName service named 'external-cloud-storage-service' with the external name 'education-edu.edu'
Command: ```bash kubectl create service externalname external-cloud-storage-service --external-name education-edu.edu ``` 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 refere...
Embed certificate authority data for the specified cluster entry
Command: ```bash kubectl config set-cluster my-k8s-cluster --embed-certs --certificate-authority=~/.kube/e2e/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluste...
Add a taint with key 'datacenter' and value 'testing-node-11:PreferNoSchedule' on nodes having the label 'service=auth'.
Command: ```bash kubectl taint node -l service=auth datacenter=testing-node-11: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": "", "usag...
Create a cluster role named "foo" with API Group specified
Command: ```bash kubectl create clusterrole foo --verb=proxy,update,patch --resource=networkpolicies.networking.k8s.io ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: ...
Set custom TLS server name for a cluster
Command: ```bash kubectl config set-cluster testing-cluster --tls-server-name=galaxy-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certif...
Create a pod using the Alpine container image and expose port 8010
Command: ```bash kubectl run hazelcast --image=alpine --port=8010 ``` 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": "--f...
Forward traffic from a local port to a specific pod and port
Command: ```bash kubectl port-forward pod/security-service-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 a...
Update the image of all containers in the 'development' daemonset to 'centos:8.4.2105'
Command: ```bash kubectl set image daemonset development *=centos:8.4.2105 ``` 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) Synta...
Create an ingress resource called 'web-ingress' that directs requests for site.com/example to the service 'svc1' on port 8010, using the tls secret 'my-cert'.
Command: ```bash kubectl create ingress web-ingress --rule="site.com/example=svc1:8010,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":...
Return the snapshot logs from the container backend-microservice-deployment-1 of the backend-pod deployment
Command: ```bash kubectl logs deployment/backend-microservice-deployment -c backend-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...
Embed the certificate authority data for the "galaxy-cluster" cluster entry
Command: ```bash kubectl config set-cluster galaxy-cluster --embed-certs --certificate-authority=~/.kube/dev-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config se...
Expose a replication controller from a YAML file with custom port mappings
Command: ```bash kubectl expose -f nginx-controller.yaml --port=8083 --target-port=808000 ``` 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 ...
Import the LOG_LEVEL key from the kube-system-config config map into the user-management-deployment deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/kube-system-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 d...
Start a pod with a CentOS image and expose port 9000.
Command: ```bash kubectl run hazelcast --image=centos --port=9000 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Create an ingress with multiple hosts and set the pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="foo.com/path*=svc:5000" \ --rule="input.com/admin*=svc2:http" ``` 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", "...
Import the CONFIG_FILE_PATH key from the app-config ConfigMap and set it as an environment variable for the mydeployment deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-config 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 o...
Create a job named "database-seeding-job" using the Ubuntu image with the command "docker run -d ubuntu sleep 3600".
Command: ```bash kubectl create job database-seeding-job --image=ubuntu -- docker run -d ubuntu sleep 3600 ``` 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": ...
Forward local port 8080 to the pod selected by the deployment 'authentication-service-deployment' on port 8080
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 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, ...
Update the image of all containers in the 'namespace-1' daemonset to 'ubuntu:20.04'
Command: ```bash kubectl set image daemonset namespace-1 *=ubuntu:20.04 ``` 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: ...
Retrieve the logs from the container "notification-handler-deployment-1" of the deployment named "analytics-pod"
Command: ```bash kubectl logs deployment/notification-handler-deployment -c analytics-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 fla...
Create an ingress resource named "app-gateway-ingress" with a rule that directs requests to site.com/input to the service "svc1" on port 8081
Command: ```bash kubectl create ingress app-gateway-ingress --rule="site.com/input=svc1:8081,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/monitoring-config deployment/api-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 defini...
Check if you have permission to list the "log-rotation-job" job in the "kube-system" namespace
Command: ```bash kubectl auth can-i list jobs.batch/log-rotation-job -n kube-system ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial U...
Execute the command "jenkins --version" in the "log-aggregator-pod" pod using the container "nebula-navigator" and retrieve the output.
Command: ```bash kubectl exec log-aggregator-pod -c nebula-navigator -- 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 na...
Forward the local port 8081 to port 8888 in the pod named 'analytics-pod'
Command: ```bash kubectl port-forward pod/analytics-pod 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 pod will be selected auto...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/global-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 definit...
Start streaming the logs of the 'cosmic-container' container in the 'proxy-service-pod' pod.
Command: ```bash kubectl logs -f -c cosmic-container proxy-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": "--contai...
Import the REDIS_HOST key from the app-secrets config map and set it as an environment variable in the web-app-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-secrets 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 ...
Create a deployment named "grafana" that runs the "node" image with 5 replicas.
Command: ```bash kubectl create deployment grafana --image=node --replicas=5 ``` 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: j...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/namespace-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...
Create a new NodePort service named "database-nodeport" that listens on port 8088 and forwards traffic to port 8010.
Command: ```bash kubectl create service nodeport database-nodeport --tcp=8088: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 local port 8088 to port 5432 in the 'analytics-pod' pod.
Command: ```bash kubectl port-forward pod/analytics-pod 8088: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...
Get deployments in the "feature-branch-2.3.0" version of the "web-apps" API group in JSON output format
Command: ```bash kubectl get deployments.feature-branch-2.3.0.web-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespa...
Create a new config map named `env-vars` with specific keys instead of file basenames on disk
Command: ```bash kubectl create configmap env-vars --from-file=settings=/path/to/profiles/file1.txt --from-file=key2=/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. When creating a c...
Add a taint with the key 'disktype' on nodes that have the label 'namespace=mynamespace'
Command: ```bash kubectl taint node -l namespace=mynamespace disktype=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": "", "us...
Embed certificate authority data for the testing-cluster cluster entry
Command: ```bash kubectl config set-cluster testing-cluster --embed-certs --certificate-authority=~/.kube/sun-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config s...
Create a copy of the e-commerce pod with a debug container and custom container images
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=my-custom-dbg --image=debian --set-image=web=nginx:latest,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and ...
copy the directory /tmp/foo_dir from the remote pod istio-system/security-scanner-pod-18 to /tmp/bar_dir on your local machine
Command: ```bash kubectl cp istio-system/security-scanner-pod-18:/tmp/foo_dir /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitte...
Set resource limits for the nginx container in the go deployment.
Command: ```bash kubectl set resources deployment go -c=nginx --limits=cpu=10,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 up to its ...
Check if you have permission to list the "data-synchronization-job" job in the "logging" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/data-synchronization-job -n logging ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a parti...
create a job called "batch-processing" with the image "postgres" and the command "psql"
Command: ```bash kubectl create job batch-processing --image=postgres -- psql ``` 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. ...
Set the service account of the deployment named 'payment-processor-deployment' to 'gitlab-runner'
Command: ```bash kubectl set serviceaccount deployment payment-processor-deployment gitlab-runner ``` 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 Syn...
Set the cluster field in the admin-context context to cluster-gamma
Command: ```bash kubectl config set contexts.admin-context.cluster cluster-gamma ``` 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 w...
Create a new secret named ldap-credentials-secret by using a file for the ssh-privatekey and a literal for the passphrase
Command: ```bash kubectl create secret generic ldap-credentials-secret --from-file=ssh-privatekey=path/to/id_rsa --from-literal=passphrase=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 ...
List the replication controller named 'web', service named 'vpn-service-rc', and pod named 'vpn-service-pod'.
Command: ```bash kubectl get rc/web service/vpn-service-rc pods/vpn-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namesp...
Retrieve the list of deployments in YAML format for the "dev-2.2.0" version of the "prod-apps" API group
Command: ```bash kubectl get deployments.dev-2.2.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 wi...
Create a single ingress called 'rontend-ingress' that directs requests to website.com/example to svc1:5001 with a tls secret "my-cert"
Command: ```bash kubectl create ingress rontend-ingress --rule="website.com/example=svc1:5001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Create a new ClusterIP service named monitoring-service-clusterip that maps port 8081 of the service to port 8443 of the target Pods
Command: ```bash kubectl create service clusterip monitoring-service-clusterip --tcp=8081:8443 ``` 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": "...
Auto scale the deployment "proxy-server" with a minimum of 6 pods and a maximum of 8 pods.
Command: ```bash kubectl autoscale deployment proxy-server --min=6 --max=8 ``` 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 ...
Forward port 6379 on all addresses to port 8000 inside the 'log-aggregator-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 6379: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...
Set the cluster field in the cluster-1-context to moon-cluster
Command: ```bash kubectl config set contexts.cluster-1-context.cluster moon-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 yo...
Import the 'secret_key' key from the 'log-config' config map into the environment variables of the 'notification-handler-deployment' deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/log-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 variable def...