prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the label of the pod named 'web' to have the key 'role' and the value 'frontend'
Command: ```bash kubectl label pods web role=frontend ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If ...
Set the service account of the deployment "monitoring-stack-deployment" to "spinnaker"
Command: ```bash kubectl set serviceaccount deployment monitoring-stack-deployment spinnaker ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: ...
Create a single ingress called 'app2-ingress' that directs requests to testing.com/module to the service svc1 on port 8010
Command: ```bash kubectl create ingress app2-ingress --rule="testing.com/module=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": "", "usag...
Mark node "worker-node-3" as unschedulable
Command: ```bash kubectl cordon worker-node-3 ``` What it does: Mark node as unschedulable. Syntax: `kubectl cordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Create a cluster role named "view" with the permission to get non-resource URLs that match the pattern /logs/*
Command: ```bash kubectl create clusterrole "view" --verb=get --non-resource-url=/logs/* ``` 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: "flag": "--output", "short": "...
Forward traffic from port 3000 on all addresses to port 8000 in the pod named proxy-server-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 3000:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Set the CPU and memory limits and requests for all containers in the "ubuntu" deployment
Command: ```bash kubectl set resources deployment ubuntu --limits=cpu=200m,memory=512Mi --requests=cpu=2,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 requeste...
Create a new ClusterIP service named my-cs, mapping port 8888 on the service to port 8000 on the pods.
Command: ```bash kubectl create service clusterip my-cs --tcp=8888:8000 ``` 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...
Update the pod 'email' by adding or updating the annotation 'custom-label' with the value 'my-custom-value'
Command: ```bash kubectl annotate --overwrite pods email custom-label='my-custom-value' ``` 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...
Create an ingress called 'internal-ingress' with the following rules: direct requests for 'testing.com/bar' to the service 'svc1:9092' and use the TLS secret 'my-cert'
Command: ```bash kubectl create ingress internal-ingress --rule="testing.com/bar=svc1:9092,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...
Copy the file "/tmp/foo" from your local machine to the directory "/tmp/bar_dir" inside the remote pod named "cache-pod-5" in the "prometheus" namespace.
Command: ```bash kubectl cp :/tmp/foo prometheus/cache-pod-5:/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, use the kubect...
Retrieve snapshot logs from the container "gateway-pod-1" of the deployment "user-management-deployment"
Command: ```bash kubectl logs deployment/user-management-deployment -c gateway-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "fl...
Create a deployment named "gateway" that uses the "wordpress" image and exposes port 8010.
Command: ```bash kubectl create deployment gateway --image=wordpress --port=8010 ``` 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...
Autoscale the replication controller "backend" to maintain a target CPU utilization of 40%, with a minimum of 1 pod and a maximum of 3 pods.
Command: ```bash kubectl autoscale rc backend --max=3 --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...
Switch to raw terminal mode and attach to the 'warp-drive' container in the 'web-app-pod' pod, sending stdin to 'bash' in the container and receiving stdout/stderr from 'bash' back to the client.
Command: ```bash kubectl attach web-app-pod -c warp-drive -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 omitted,...
Add an annotation to a pod specified in the "preferences.json" file
Command: ```bash kubectl annotate -f preferences.json last-deployment=2023-03-15 ``` 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 incl...
Return the snapshot logs from all containers in the pod named "mypod"
Command: ```bash kubectl logs mypod --all-containers=true ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short"...
Create a job named 'log-processing-job' using the 'centos' image that sleeps for 3600 seconds.
Command: ```bash kubectl create job log-processing-job --image=centos -- 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...
Delete the pods and services named "proxy-server" and "api"
Command: ```bash kubectl delete pod,service proxy-server api ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector...
Update the pod 'database' with the annotation 'app-version' and the value '2.5.1'
Command: ```bash kubectl annotate pods database app-version=2.5.1 ``` 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 s...
List specific resources by their type and names
Command: ```bash kubectl get rc/web service/security-service-rc pods/backend-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 names...
Start a centos pod, but customize the pod specifications using JSON overrides
Command: ```bash kubectl run nginx --image=centos --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] [--command] -- [COMMAN...
View the options available for all kubectl commands.
Command: ```bash kubectl options ``` What it does: Print the list of flags inherited by all commands Syntax: `kubectl options`
Create a job named 'batch-processing' using the nginx image and the command 'nginx'
Command: ```bash kubectl create job batch-processing --image=nginx -- nginx ``` 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...
List deployments in the "stable-2.0.0" version of the "alpha-apps" API group in YAML format.
Command: ```bash kubectl get deployments.stable-2.0.0.alpha-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 yo...
Use the "micro" editor to edit the "email-service" service
Command: ```bash KUBE_EDITOR="micro" kubectl edit svc/email-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,...
Get the output from running the 'redis-cli' command in the first container of the 'mydeployment' deployment.
Command: ```bash kubectl exec deploy/mydeployment -- redis-cli ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kub...
Expose a service for the specified replication controller, with a specific port configuration.
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=3001 --target-port=900000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the...
List deployments in JSON output format of the "web-apps" API group in version "v2.0.0" using the command "kubectl get deployments.v2.0.0.web-apps -o json"
Command: ```bash kubectl get deployments.v2.0.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 namespaced you will o...
Retrieve the output from running the command 'apache2ctl -D FOREGROUND' in the container 'quantum-quark' from the pod 'log-aggregator-pod'
Command: ```bash kubectl exec log-aggregator-pod -c quantum-quark -- apache2ctl -D FOREGROUND ``` 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": "Containe...
Forward traffic from port 8081 on all addresses to port 6379 in the frontend-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 8081: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...
Forward traffic from port 6379 on all addresses to port 8080 inside the proxy-server-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 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 ...
View the differences between the resources defined in docker-registry.yaml and the current state in the cluster
Command: ```bash kubectl diff -f docker-registry.yaml ``` What it does: Diff configurations specified by file name or stdin between the current online configuration, and the configuration as it would be if applied. The output is always YAML. KUBECTL_EXTERNAL_DIFF environment variable can be used to select your own dif...
Import only the 'smtp_server' key from the 'kube-system-config' ConfigMap into the environment variables of the 'email-server-deployment' Deployment
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/kube-system-config deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Import specific keys from a config map to a deployment's environment variables.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-secrets deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Import environment variables from a secret to a deployment
Command: ```bash kubectl set env --from=secret/oauth-secret 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 definitions in one or ...
Add a taint with key 'special' on nodes having label stack=tech-stack
Command: ```bash kubectl taint node -l stack=tech-stack special=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Create a Pod Disruption Budget named 'auth-service-pdb' that selects all pods with the 'region=us-east' label and ensures that at least four of them are available at any point in time.
Command: ```bash kubectl create poddisruptionbudget auth-service-pdb --selector=region=us-east --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=...
Set the cluster field in the my-context context to cloud-cluster.
Command: ```bash kubectl config set contexts.user-b-context.cluster cloud-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 ...
Set the CPU and memory limits for the MySQL container in the deployment called "mysql".
Command: ```bash kubectl set resources deployment mysql -c=nginx --limits=cpu=200m,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to i...
Add a taint with key 'hardware' on the node(s) having the label 'zone=us-east-1', specifically on the node with name 'node-2' and set the taint effect to 'PreferNoSchedule'
Command: ```bash kubectl taint node -l zone=us-east-1 hardware=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": "Outp...
Create a job using the Alpine image with the command "ash"
Command: ```bash kubectl create job audit-job --image=alpine -- ash ``` 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: js...
Create a copy of the 'cdn-service-pod' pod and change all container images to 'redis'
Command: ```bash kubectl debug cdn-service-pod --copy-to=debug-image-app --set-image=*=redis ``` 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 r...
Set the cluster field in the specified context to the provided value
Command: ```bash kubectl config set contexts.on-prem-context.cluster galaxy-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...
Copy the local file /tmp/foo to the remote pod named 'image-resizer-pod-20' in the 'monitoring' namespace, and place it in the /etc/kubernetes directory.
Command: ```bash kubectl cp /tmp/foo monitoring/image-resizer-pod-20:/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...
Start a pod named 'busybox' using the 'ubuntu' image, and keep it running in the foreground
Command: ```bash kubectl run -i -t busybox --image=ubuntu --restart=Never ``` 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: "fla...
Set the cluster field in the "my-context" context to "star-cluster"
Command: ```bash kubectl config set contexts.app-1-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...
Specify the resource request and limits for all containers in the postgres deployment
Command: ```bash kubectl set resources deployment postgres --limits=cpu=200m,memory=512Mi --requests=cpu=50m,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 reques...
If the deployment named 'web' currently has a size of 1, scale the 'mysql' deployment to a size of 1.
Command: ```bash kubectl scale --current-replicas=1 --replicas=1 deployment/web ``` 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...
Get the output from the 'code-explorer' container in the 'media-stream-pod' pod.
Command: ```bash kubectl attach media-stream-pod -c code-explorer ``` 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...
Add a taint with key 'app' on nodes having label cluster=my-cluster
Command: ```bash kubectl taint node -l cluster=my-cluster app=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Create an ingress named 'private-service-ingress' with a rule that directs requests for testing.com/input to svc1:8083
Command: ```bash kubectl create ingress private-service-ingress --rule="testing.com/input=svc1:8083,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 secret named cert-manager-secret with keys for each file in folder bar with the files located in path/to/parameters
Command: ```bash kubectl create secret generic cert-manager-secret --from-file=path/to/parameters ``` 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 basena...
Provide detailed information about the logging-agent-pod pod
Command: ```bash kubectl describe pods/logging-agent-pod ``` 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, prov...
Update the annotation 'git-repo' of the pod 'security' to 'https://github.com/example/my-app'
Command: ```bash kubectl annotate pods security 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 lab...
Create a cron job named "log-rotation" that runs a Python command every minute.
Command: ```bash kubectl create cronjob log-rotation --image=python --schedule="*/1 * * * *" -- python ``` 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", "de...
Set the client-key-data field for the developer user by providing the certificate data using the --set-raw-bytes option.
Command: ```bash kubectl config set users.developer.client-key-data cert_data_here --set-raw-bytes=true ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE...
Create a cron job named 'email-notifications' with the image 'mcr.microsoft.com/dotnet/core/runtime', a schedule of running every minute, and a command to list runtimes in the dotnet core framework.
Command: ```bash kubectl create cronjob email-notifications --image=mcr.microsoft.com/dotnet/core/runtime --schedule="*/1 * * * *" -- dotnet --list-runtimes ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` ...
Forward port 8000 on your localhost and IP 10.19.21.23 to port 5000 in the pod named "mypod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8000:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a p...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-name-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 on...
Create a debug copy of the 'vpn-service-pod' pod with all container images changed to 'amazonlinux'
Command: ```bash kubectl debug vpn-service-pod --copy-to=debug-image-api --set-image=*=amazonlinux ``` 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 i...
Start a pod named 'hazelcast' using the 'node' image and expose port 27017
Command: ```bash kubectl run hazelcast --image=node --port=27017 ``` 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...
Enable the OpenID Connect auth provider for the "app-service" entry with additional args
Command: ```bash kubectl config set-credentials app-service --auth-provider=oidc --auth-provider-arg=client-id=foo --auth-provider-arg=client-secret=bar ``` 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: -...
Forward connections on port 8081 from both localhost and IP 10.19.21.23 to port 8000 in the log-aggregator-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 8081:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the ...
Create a new config map named global-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap global-config --from-file=settings=/path/to/settings/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 creatin...
Retrieve the output of the 'npm --version' command from the first pod of the email server deployment.
Command: ```bash kubectl exec deploy/email-server-deployment -- npm --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 omitt...
Retrieve snapshot logs from container "media-stream-pod-1" in the deployment named "mydeployment".
Command: ```bash kubectl logs deployment/mydeployment -c media-stream-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": "--c...
Forward requests from port 8000 on your local machine to port 6379 inside the 'chat-app-pod' pod
Command: ```bash kubectl port-forward pod/chat-app-pod 8000:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create an ingress named 'frontend-ingress' that routes requests for website.com/bar to svc1:9092 using the tls secret 'my-cert'
Command: ```bash kubectl create ingress rontend-ingress --rule="website.com/bar=svc1:9092,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create an ingress resource named 'web-ingress' and configure it to direct requests from 'foo.com/example' to the service 'svc1' on port 3306
Command: ```bash kubectl create ingress web-ingress --rule="foo.com/example=svc1:3306,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 new secret named "my-secret" from an environment file
Command: ```bash kubectl create secret generic my-secret --from-env-file=path/to/options.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 of...
Set the custom TLS server name to use for validation for the staging-cluster cluster entry as "data-cluster"
Command: ```bash kubectl config set-cluster staging-cluster --tls-server-name=data-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...
Create a deployment named "jenkins" with the image "jenkins" and the command "jenkins --version"
Command: ```bash kubectl create deployment jenkins --image=jenkins -- jenkins --version ``` 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...
Embed the certificate authority data for the kube-cluster-2 cluster entry by running the command: `kubectl config set-cluster kube-cluster-2 --embed-certs --certificate-authority=~/.kube/cluster-gamma/kubernetes.ca.crt`
Command: ```bash kubectl config set-cluster kube-cluster-2 --embed-certs --certificate-authority=~/.kube/cluster-gamma/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 ...
Apply the last-applied configuration to each file in a directory
Command: ```bash kubectl apply set-last-applied -f params/ ``` 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 o...
Create a new ClusterIP service named payment-service-clusterip, mapping port 8082 on the service to port 8088 on the target
Command: ```bash kubectl create service clusterip payment-service-clusterip --tcp=8082:8088 ``` 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"...
Attach to the 'stardust-shuttle' container in the 'proxy-service-pod' pod and get the output.
Command: ```bash kubectl attach proxy-service-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 om...
Create a service for a replicated Ruby application that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose rc ruby --port=8082 --target-port=8000 ``` 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 d...
Set the cluster field in the context named 'my-context' to 'dev-cluster'
Command: ```bash kubectl config set contexts.user-b-context.cluster dev-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 job named "deployment-rollout-job" using the Redis image and run the Redis server inside the job.
Command: ```bash kubectl create job deployment-rollout-job --image=redis -- redis-server ``` 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": "Outp...
Execute the 'elasticsearch-plugin --list' command in the nebula-navigator container inside the e-commerce-pod pod.
Command: ```bash kubectl exec e-commerce-pod -c nebula-navigator -- elasticsearch-plugin --list ``` 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...
Retrieve the output from running the 'nginx' command inside the 'quantum-quark' container of the 'email-service-pod' pod.
Command: ```bash kubectl exec email-service-pod -c quantum-quark -- 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, ...
Forward local port 5000 to port 8080 in the security-service-pod pod.
Command: ```bash kubectl port-forward pod/security-service-pod 5000: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 new config map named app-settings using the specified files as sources for key-value pairs
Command: ```bash kubectl create configmap app-settings --from-file=conf=/path/to/configs/file1.txt --from-file=data=/path/to/preferences/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...
create a deployment named auth using the centos image and expose port 27017
Command: ```bash kubectl create deployment auth --image=centos --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: js...
Retreive the logs of the previously terminated "warp-drive" container from the pod "vpn-service-pod"
Command: ```bash kubectl logs -p -c warp-drive vpn-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", "s...
Create a new config map named kube-system-config in the current namespace, using the specified files as key-value pairs
Command: ```bash kubectl create configmap kube-system-config --from-file=properties=/path/to/configurations/file1.txt --from-file=key1=/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. W...
Set the custom TLS server name 'on-prem-cluster' for the 'edge-cluster' cluster entry.
Command: ```bash kubectl config set-cluster edge-cluster --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...
Create a new LoadBalancer service named 'proxy-server-lb' that forwards traffic from port 8083 to port 9092.
Command: ```bash kubectl create service loadbalancer proxy-server-lb --tcp=8083:9092 ``` 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", "de...
Create a debug copy of the 'proxy-service-pod' by changing all container images to 'centos' and name it 'debug-image-app'.
Command: ```bash kubectl debug proxy-service-pod --copy-to=debug-image-app --set-image=*=centos ``` 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 n...
Create a service for the specified replication controller with the specified configuration
Command: ```bash kubectl expose -f wordpress-controller.yaml --port=7000 --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 ...
Display the resource usage metrics for the 'auth-service-pod' pod, including its containers
Command: ```bash kubectl top pod auth-service-pod --containers ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl top ...
List all deployments in the "stable-2.0.0" version of the "prod-apps" API group in JSON output format.
Command: ```bash kubectl get deployments.stable-2.0.0.prod-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...
Forward traffic from port 6379 on localhost and IP 10.19.21.23 to port 5000 in the pod named api-service-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 6379: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 cri...
Update the cluster field in the my-context context to data-cluster
Command: ```bash kubectl config set contexts.user-a-context.cluster data-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 w...
Create a priority class named emergency-priority with a value of 200000, a description of "Immediate, emergency resource allocation", and a preemption policy set to "Never".
Command: ```bash kubectl create priorityclass emergency-priority --value=200000 --description="Immediate, emergency resource allocation" --preemption-policy="Never" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --val...
Retrieve a list of deployments in JSON format from the "stable-2.0.0" version of the "my-apps" API group.
Command: ```bash kubectl get deployments.stable-2.0.0.my-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 pod named "hazelcast" using the "mongo" image and expose port 8088
Command: ```bash kubectl run hazelcast --image=mongo --port=8088 ``` 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 deployment named jenkins using the confluentinc/cp-kafka image and expose port 3306
Command: ```bash kubectl create deployment jenkins --image=confluentinc/cp-kafka --port=3306 ``` 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 f...
Set the custom TLS server name to "e2e" for the edge-cluster cluster entry
Command: ```bash kubectl config set-cluster edge-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-authorit...