prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Scale a resource specified in "settings.json" to 3 replicas
Command: ```bash kubectl scale --replicas=3 -f settings.json ``` 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 specified, it is valida...
Set the environment variables 'API_KEY' in the deployment 'notification-handler-deployment' using the values from the 'global-config' config map.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/global-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...
Partially update a node using a strategic merge patch, specifying the patch as a JSON object
Command: ```bash kubectl patch node storage-node-13 -p '{"spec":{"replicas":3}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful fl...
Create a copy of the "mypod" pod and change all container images to use the "ubuntu" image.
Command: ```bash kubectl debug mypod --copy-to=dgb-img --set-image=*=ubuntu ``` 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 resource is specif...
Forward local port 5432 to port 8088 in the backend pod
Command: ```bash kubectl port-forward pod/backend-pod 5432 8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Create an ingress named 'private-ingress' that routes requests from site.com/input to svc1:5001 and uses a TLS secret named "my-cert"
Command: ```bash kubectl create ingress private-ingress --rule="site.com/input=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": "", "usage...
Create a copy of the media-stream-pod with a debug container and updated container images
Command: ```bash kubectl debug media-stream-pod -it --copy-to=debug-image-1 --image=debian --set-image=proxy=nginx:1.21,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 identified b...
List the deployments in the "experimental-apps" API group with version "v2.1.0" in JSON format.
Command: ```bash kubectl get deployments.v2.1.0.experimental-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 y...
List the deployments in the "external-apps" API group, using the "v1.0.0" version, and display the results in JSON format.
Command: ```bash kubectl get deployments.v1.0.0.external-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 you w...
Create a priority class named 'finance-priority' with a value of 250 and a description of "Priority for financial services and tasks"
Command: ```bash kubectl create priorityclass finance-priority --value=250 --description="Priority for financial services and tasks" ``` 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 [...
Create a new ExternalName service named external-geolocation-service with the external name documentation-tech.tech
Command: ```bash kubectl create service externalname external-geolocation-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 re...
Set the CPU and memory limits and requests for all containers in the elasticsearch deployment.
Command: ```bash kubectl set resources deployment elasticsearch --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=2Gi ``` 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 ...
Add a taint with key 'disktype' on nodes having label service=auth. Apply the taint 'PreferNoSchedule' on the 'db-node-7' node.
Command: ```bash kubectl taint node -l service=auth disktype=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": "Out...
Open the 'user-service' service for editing using the 'micro' text editor
Command: ```bash KUBE_EDITOR="micro" kubectl edit svc/user-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 variables, ...
View the last-applied-configuration annotations of the resource defined in the 'conf.yaml' file in JSON format.
Command: ```bash kubectl apply view-last-applied -f conf.yaml -o json ``` 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-appl...
Create a deployment named 'jenkins-x' with the 'mongo' image and expose port 8082
Command: ```bash kubectl create deployment jenkins-x --image=mongo --port=8082 ``` 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 debug container for the cdn-service-pod, copy it to a new image called debug-image-memcached, and change the images of the containers within the pod to debian and mysql:5.7 respectively.
Command: ```bash kubectl debug cdn-service-pod -it --copy-to=debug-image-memcached --image=debian --set-image=database=mysql:5.7,database=mysql:5.7 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by ...
Forward port 8000 from localhost and IP 10.19.21.23 to port 8000 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 8000:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the ...
Copy the file "/var/run/secrets/kubernetes.io/serviceaccount/" from your local machine to the "/tmp/bar" path in the "task-processor-pod-17" pod
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ task-processor-pod-17:/tmp/bar -c monitoring-agent ``` 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": "", ...
Forward local port 6379 to port 8080 on the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward pod/e-commerce-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 aut...
List the specified resources by their types and names.
Command: ```bash kubectl get rc/web service/backend-rc pods/cdn-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 namespaced...
Create a new cluster role named "custom_role" with specific resource names
Command: ```bash kubectl create clusterrole custom_role --verb=use --resource=pods --resource-name=report-generator --resource-name=file-uploader ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cli...
Create a role named "custom_role" with the specified ResourceName
Command: ```bash kubectl create role custom_role --verb=proxy --resource=pods --resource-name=message-queue --resource-name=auth-service ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=serve...
Get output from running the 'psql' command in the cdn-service-pod container.
Command: ```bash kubectl exec cdn-service-pod -- psql ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kube...
Create a copy of the security-service-pod and launch an interactive shell in the astro-container of the copied pod
Command: ```bash kubectl debug security-service-pod -it --copy-to=my-debugger --container=astro-container -- sh ``` 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...
Create a pod disruption budget named statefulset-pdb that will select all pods with the role=worker label and ensure that at least one of them is always available.
Command: ```bash kubectl create poddisruptionbudget statefulset-pdb --selector=role=worker --min-available=1 ``` 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=N [-...
Create a single ingress called 'app-loadbalancer-ingress' that directs requests to site.com/input to svc1:8010 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="site.com/input=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": "...
Update the user field for the edge-context context entry to "cluster-admin" without modifying any other values.
Command: ```bash kubectl config set-context edge-context --user=cluster-admin ``` What it does: Set a context 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-context [NAME | --current] [--cluster=cluster_nickname]...
Create a new ClusterIP service named my-cs with a TCP port mapping from port 3000 to port 8443
Command: ```bash kubectl create service clusterip my-cs --tcp=3000: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": "-o", "default": "", "us...
Forward traffic from local port 5432 to port 9090 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 5432: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 auto...
Auto scale the replication controller "proxy" with the following configuration:
Command: ```bash kubectl autoscale rc proxy --max=6 --cpu-percent=40 ``` 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 t...
Create a new config map named app-name-config using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-name-config --from-file=conf=/path/to/configurations/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 creat...
Add a taint with key 'disktype' on nodes having the label 'namespace=mynamespace', and the taint value 'PreferNoSchedule' on the node named 'testing-node-11'
Command: ```bash kubectl taint node -l namespace=mynamespace disktype=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": ""...
Update the 'cdn' pod and set the annotation 'git-repo' to 'https://github.com/example/my-app'.
Command: ```bash kubectl annotate pods cdn 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 than labels a...
Forward local port 8888 to port 5432 in a pod selected by the deployment "analytics-platform-deployment"
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 8888 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...
Start a hazelcast pod with the nginx name and the hazelcast/hazelcast image, but override the specification with a partial set of values parsed from a JSON file
Command: ```bash kubectl run nginx --image=hazelcast/hazelcast --overrides='{ "apiVersion": "v1.1.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...
Create a Jenkins deployment with the image "jenkins" and expose port 3001.
Command: ```bash kubectl create deployment jenkins --image=jenkins --port=3001 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of:...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-settings 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 defini...
Remove the label named 'app' from the 'payment' pod
Command: ```bash kubectl label pods payment app- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If true,...
Create a service for the php-controller replication controller specified in the "php-controller.yaml" file, serving on port 80 and connecting to the containers on port 8080.
Command: ```bash kubectl expose -f php-controller.yaml --port=80 --target-port=808100 ``` 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 role binding for multiple users and a group using a specific cluster role
Command: ```bash kubectl create rolebinding admin --clusterrole=admin --user=user1 --user=user2 --group=group1 ``` 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] [--serviceaccount=...
Forward traffic from all addresses on port 5000 to the CDN service pod's port 5000.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 5000: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 w...
Create a new ClusterIP service named 'backend-service-clusterip' that forwards traffic from port 9000 to port 8083 using TCP protocol
Command: ```bash kubectl create service clusterip backend-service-clusterip --tcp=9000:8083 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o"...
Show all logs from the payment-gateway-pod pod written in the last hour
Command: ```bash kubectl logs --since=1h payment-gateway-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 /var/run/secrets/kubernetes.io/serviceaccount/ directory from the 'image-resizer-pod-20' pod to the /etc/kubernetes directory on the local machine
Command: ```bash kubectl cp openfaas/image-resizer-pod-20:/var/run/secrets/kubernetes.io/serviceaccount/ /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usag...
Create an ingress named "ingress1" with multiple hosts and set the pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="foo.com/path*=svc:9090" \ --rule="module.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", ...
Create a deployment named "registry" using the "ruby" image
Command: ```bash kubectl create deployment registry --image=ruby ``` 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: json|yaml|nam...
List resources by their type and names
Command: ```bash kubectl get rc/web service/web-app-rc pods/e-commerce-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 namespaced ...
Rename a context in kubeconfig file
Command: ```bash kubectl config rename-context local-context edge-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will also b...
Copy the local file "/var/run/secrets/kubernetes.io/serviceaccount/" to the remote pod named "metrics-exporter-pod-10" in the "kube-flannel" namespace, and place it in the "/etc/kubernetes" directory.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ kube-flannel/metrics-exporter-pod-10:/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": ""...
Set the resource request to 5 CPU and 128Mi memory, and limits to 200m CPU and 512Mi memory for all containers in the centos deployment
Command: ```bash kubectl set resources deployment centos --limits=cpu=200m,memory=512Mi --requests=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 requeste...
Remove the 'description' annotation from the 'payment' pod
Command: ```bash kubectl annotate pods payment 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 ...
Retrieve the output of the 'ruby --version' command from the code-explorer container in the auth-service-pod
Command: ```bash kubectl exec auth-service-pod -c code-explorer -- ruby --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 o...
Start a wordpress pod named nginx, but override the spec with a partial set of values parsed from JSON
Command: ```bash kubectl run nginx --image=wordpress --overrides='{ "apiVersion": "beta-1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [C...
Create a service for the 'alpine' replica set, which serves on port 8181 and connects to the containers on port 8000.
Command: ```bash kubectl expose rs alpine --port=8181 --target-port=800000 ``` 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 an ingress called 'app-gateway-ingress' with a rule that directs requests from 'testing.com/example' to 'svc1:3000' using the TLS secret "my-cert".
Command: ```bash kubectl create ingress app-gateway-ingress --rule="testing.com/example=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": "...
Create a new config map named env-vars by using the files file1.txt and file2.txt, located at /path/to/preferences/ and /path/to/profiles/ respectively.
Command: ```bash kubectl create configmap env-vars --from-file=conf=/path/to/preferences/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 conf...
Update the annotation 'expiration-date' of the pod 'proxy-server' with the value '2024-12-31', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods proxy-server 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 lab...
Start streaming the logs of the "cyber-sleuth" container in the "chat-app-pod" pod.
Command: ```bash kubectl logs -f -c cyber-sleuth 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", "sh...
Execute the 'geth attach' command in the container 'lunar-launcher' from the pod 'monitoring-pod'
Command: ```bash kubectl exec monitoring-pod -c lunar-launcher -- geth attach ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitt...
Forward traffic from local port 8000 to port 8088 in the 'web-app-pod' pod
Command: ```bash kubectl port-forward pod/web-app-pod 8000:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Add a taint on nodes in the 'us-east-1' zone with the key 'app' and the value 'testing-node-11' and set the effect to 'PreferNoSchedule'
Command: ```bash kubectl taint node -l zone=us-east-1 app=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": "", "usage": "...
Create a new ingress called 'service-ingress' with a rule that directs requests for site.com/example to svc1:8081
Command: ```bash kubectl create ingress service-ingress --rule="site.com/example=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": "", "usa...
Embed client certificate data in the "app-service" entry
Command: ```bash kubectl config set-credentials app-service --client-certificate=~/.kube/admin.crt --embed-certs=true ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --clie...
Copy the file named "foo" from the remote pod "task-processor-pod-17" in the namespace "velero" to the local directory "/etc/kubernetes".
Command: ```bash kubectl cp velero/task-processor-pod-17:/tmp/foo /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Set resource requests and limits for all containers in the mysql deployment.
Command: ```bash kubectl set resources deployment mysql --limits=cpu=200m,memory=512Mi --requests=cpu=500m,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 request...
Add a taint to the nodes with label version=v1.0.0
Command: ```bash kubectl taint node -l version=v1.0.0 environment=monitoring-node-15: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": "",...
Create a deployment named "prometheus" using the "jenkins" image, and expose port 7000.
Command: ```bash kubectl create deployment prometheus --image=jenkins --port=7000 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One ...
Forward local port 8088 to port 8080 in the 'mypod' pod
Command: ```bash kubectl port-forward pod/mypod 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 criteria, a pod will be selected automaticall...
Forward local port 9090 to port 9090 in the pod 'api-service-pod'
Command: ```bash kubectl port-forward pod/api-service-pod 9090:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Retrieve the previous terminated logs of the "nebula-navigator" container from the "chat-app-pod" pod.
Command: ```bash kubectl logs -p -c nebula-navigator 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",...
Partially update the node named web-node-8 by applying a strategic merge patch that sets the password to "new-password".
Command: ```bash kubectl patch node web-node-8 -p $'stringData:\n password: new-password' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` ...
Start a redis pod with the name 'nginx' and the image 'redis', but override the spec with a partial set of values parsed from the provided JSON
Command: ```bash kubectl run nginx --image=redis --overrides='{ "apiVersion": "hotfix-1.1.2", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [C...
Add a taint with key 'cpu-type' and no value to the 'web-node-8' node.
Command: ```bash kubectl taint nodes web-node-8 cpu-type:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: j...
View the details of a specific revision of a daemonset
Command: ```bash kubectl rollout history daemonset/prod --revision=7 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to fi...
Get the output of the `composer --version` command from the first container of the `order-service` service.
Command: ```bash kubectl exec svc/order-service -- composer --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 ...
Update the deployment 'web-app-deployment' with a new environment variable.
Command: ```bash kubectl set env deployment/web-app-deployment DEBUG=true ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates (within re...
Scale the replication controller "chat-app" with the number of pods between 1 and 7, targeting a CPU utilization of 60%.
Command: ```bash kubectl autoscale rc chat-app --max=7 --cpu-percent=60 ``` 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...
Create a service for a replicated centos using replica set, serving on port 80 and connecting to the containers on port 8000
Command: ```bash kubectl expose rs centos --port=80 --target-port=808200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
Set the "client-key" field of the "k8s-admin" entry with the key located at "~/.kube/admin.key"
Command: ```bash kubectl config set-credentials k8s-admin --client-key=~/.kube/admin.key ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=keyfile Bearer token f...
Create a new ingress resource called 'private-api-ingress' with a rule that directs requests to the 'testing.com/module' path to the 'svc1' service on port 8000
Command: ```bash kubectl create ingress private-api-ingress --rule="testing.com/module=svc1:8000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ""...
Import the SMTP_SERVER key from the global-config config map and set it as an environment variable in the gateway-deployment deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/global-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 ...
Create a copy of the 'payment-gateway-pod' and launch an interactive shell inside the 'cyber-sleuth' container by running the command: kubectl debug payment-gateway-pod -it --copy-to=my-debugger --container=cyber-sleuth -- sh
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=my-debugger --container=cyber-sleuth -- sh ``` 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 ...
Delete the pod named "mypod" and wait for it to be deleted, with a timeout of 60 seconds
Command: ```bash kubectl delete pod/mypod kubectl wait --for=delete pod/busybox1 --timeout=60s ``` What it does: Experimental: Wait for a specific condition on one or many resources. The command takes multiple resources and waits until the specified condition is seen in the Status field of every given resource. Altern...
Create a new config map named app-config-dev using key=value pairs from a file.
Command: ```bash kubectl create configmap app-config-dev --from-file=path/to/parameters ``` 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 base...
create a deployment named drupal using the mongo image
Command: ```bash kubectl create deployment drupal --image=mongo ``` 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: json|yaml|name...
Add a taint with key 'zone' on nodes having label myLabel, set the value to 'app-node-6' and the effect to 'PreferNoSchedule'
Command: ```bash kubectl taint node -l myLabel 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": "Output form...
Create a new ClusterIP service named 'order-service-clusterip' that maps port 8000 to port 3000
Command: ```bash kubectl create service clusterip order-service-clusterip --tcp=8000:3000 ``` 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 deployment named db with ubuntu image and expose port 3000
Command: ```bash kubectl create deployment db --image=ubuntu --port=3000 ``` 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: json|...
Create a new copy of the "monitoring-pod" by adding a debug container and changing the container images
Command: ```bash kubectl debug monitoring-pod -it --copy-to=debug-image-app --image=debian --set-image=mailer=mailer:latest,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by res...
Taint nodes with label 'environment=production' using key 'special' with the value 'web-node-8' and scheduling preference of 'PreferNoSchedule'
Command: ```bash kubectl taint node -l environment=production special=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": "", "us...
Forward traffic from port 8000 on localhost and IP 10.19.21.23 to port 5000 in the pod "security-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 8000:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching th...
Set the cluster field in the prod-context context to star-cluster.
Command: ```bash kubectl config set contexts.prod-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 wan...
Import specific keys from a config map into the environment variables of a deployment for a monitoring stack.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-secrets 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 definit...
Forward port 5000 on your local machine to port 8081 in the pod named "mypod"
Command: ```bash kubectl port-forward pod/mypod 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 automaticall...
Add a taint to node 'app-node-6' with the key 'special' and no value specified.
Command: ```bash kubectl taint nodes app-node-6 special: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...
Create an ingress named ingtls with TLS enabled using the default ingress certificate
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="site.com/=svc:https,tls" \ --rule="site.com/path/subpath*=othersvc:8088" ``` 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": "--o...
Create an ingress called 'internal-ingress' that routes requests to testing.com/module to a service named svc1 on port 7000 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress internal-ingress --rule="testing.com/module=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": "", "...
Forward all traffic from port 9090 on all addresses to port 5000 in the 'proxy-server-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-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 ...
create ingress called 'app2-ingress' with a rule that directs requests from 'foo.com/input' to 'svc1:5001' using tls secret 'my-cert'
Command: ```bash kubectl create ingress app2-ingress --rule="foo.com/input=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": "", "usage": "...