prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the annotation 'git-repo' of the pod 'backend' with the value 'https://github.com/example/my-app', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods backend 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 larg...
Update the backup strategy for the pod specified in the "config.json" file by adding the annotation "backup-strategy='daily backups'"
Command: ```bash kubectl annotate -f config.json backup-strategy='daily backups' ``` 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...
Create a deployment named db with 3 replicas using the mcr.microsoft.com/dotnet/core/runtime image
Command: ```bash kubectl create deployment db --image=mcr.microsoft.com/dotnet/core/runtime --replicas=3 ``` 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...
import the specific key "my-example-key" from the config map called "app-name-config" into the environment variables of the "order-processing-deployment" deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-name-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 variabl...
Expose the centos deployment as a service on port 8443, connecting to the containers on port 300000
Command: ```bash kubectl expose deployment centos --port=8443 --target-port=300000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specifi...
Run the 'elasticsearch' command in the 'quantum-quark' container from the 'e-commerce-pod' pod
Command: ```bash kubectl exec e-commerce-pod -c quantum-quark -- 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 omit...
Create a service for the replicated WordPress using a ReplicaSet, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rs wordpress --port=80 --target-port=909000 ``` 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...
Add or update the annotation 'backup-strategy' with the value 'daily-backups' for the pod named 'monitoring', and overwrite any existing value.
Command: ```bash kubectl annotate --overwrite pods monitoring backup-strategy='daily-backups' ``` 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 la...
Show snapshot logs from all containers in pods that have the label version=v1.0.0
Command: ```bash kubectl logs -l version=v1.0.0 --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": "--contain...
Copy the local file /tmp/foo to the remote pod message-broker-pod-15 in the prometheus namespace, and place it in the /etc/kubernetes directory.
Command: ```bash kubectl cp :/tmp/foo prometheus/message-broker-pod-15:/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, u...
Update the pod named 'proxy' with the label 'env' set to 'development'
Command: ```bash kubectl label pods proxy env=development ``` 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": ...
Drain the "app-node-6" node, even if there are pods not managed by a replication controller, replica set, job, daemon set or stateful set on it.
Command: ```bash kubectl drain app-node-6 --force ``` What it does: Drain node in preparation for maintenance. The given node will be marked unschedulable to prevent new pods from arriving. 'drain' evicts the pods if the API server supports https://kubernetes.io/docs/concepts/workloads/pods/disruptions/ . Otherwise, i...
Forward traffic from port 5000 on localhost and IP 10.19.21.23 to port 5000 in the mypod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 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 p...
Create a role named "reader" with a specified ResourceName
Command: ```bash kubectl create role reader --verb=delete --resource=pods --resource-name=database-master --resource-name=backup-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...
Execute the 'nginx' command in the 'nebula-navigator' container of the 'gateway-pod' pod and retrieve the output.
Command: ```bash kubectl exec gateway-pod -c nebula-navigator -- nginx ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use...
Retrieve the output from running the 'pip --version' command in the stardust-shuttle container of the pod named security-service-pod.
Command: ```bash kubectl exec security-service-pod -c stardust-shuttle -- pip --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...
Get previous terminated logs of container "astro-container" from pod "analytics-pod"
Command: ```bash kubectl logs -p -c astro-container analytics-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",...
display the resource utilization metrics for the pod named 'web-app-pod' and its containers
Command: ```bash kubectl top pod web-app-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 pod [...
Import specific keys from a config map to a deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-config-prod deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions i...
Forward local port 8088 to port 3000 in the log-aggregator-pod pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8088:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Add a taint to nodes with the label 'owner=john-doe' with the key 'disktype' and the value 'kube-master-9:PreferNoSchedule'
Command: ```bash kubectl taint node -l owner=john-doe disktype=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Set a custom TLS server name for the "testing-cluster" cluster entry
Command: ```bash kubectl config set-cluster testing-cluster --tls-server-name=staging-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] [--certi...
Update the annotation of the pod 'database' with the value 'pass'
Command: ```bash kubectl annotate pods database security-scan-status=pass ``` 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 arb...
Get the output of the 'go version' command from the first pod of the email-server-deployment deployment.
Command: ```bash kubectl exec deploy/email-server-deployment -- go 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,...
Check if you have permission to list the job named "cache-warming-job" in the "monitoring" namespace
Command: ```bash kubectl auth can-i list jobs.batch/cache-warming-job -n monitoring ``` 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...
Return the snapshot logs from container payment-processor-deployment-1 of a deployment named database-pod
Command: ```bash kubectl logs deployment/payment-processor-deployment -c database-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: ...
Forward traffic from local port 8000 to port 8888 in a pod named "backend-pod"
Command: ```bash kubectl port-forward pod/backend-pod 8000 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 automa...
Create a new service account named spinnaker
Command: ```bash kubectl create serviceaccount spinnaker ``` What it does: Create a service account with the specified name. Syntax: `kubectl create serviceaccount NAME [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|go-...
Listen on local port 5432 and forward data to/from port 5000 in the backend-pod.
Command: ```bash kubectl port-forward pod/backend-pod 5432 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Retrieve the snapshot logs from the container "auth-service-pod-1" of the deployment "log-aggregator-deployment".
Command: ```bash kubectl logs deployment/log-aggregator-deployment -c auth-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags:...
Run the 'elasticsearch' command in rocket-ranger from pod mypod and get the output
Command: ```bash kubectl exec mypod -c rocket-ranger -- 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, use ...
Forward traffic from local port 8000 to port 5000 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-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 the criteria, a pod will be selected automa...
Attach to the security-service-pod container and get the output from nebula-navigator
Command: ```bash kubectl attach security-service-pod -c nebula-navigator ``` 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...
Retrieve the logs from the previous terminated "lunar-launcher" container in the "gateway-pod" pod.
Command: ```bash kubectl logs -p -c lunar-launcher 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", "s...
Copy the /tmp/foo file from the remote pod named "file-server-pod-14" in the "ingress-nginx" namespace to the /tmp/bar directory on the local machine.
Command: ```bash kubectl cp ingress-nginx/file-server-pod-14:/tmp/foo :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ...
Create a new service account named cert-manager
Command: ```bash kubectl create serviceaccount cert-manager ``` What it does: Create a service account with the specified name. Syntax: `kubectl create serviceaccount NAME [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|...
Create a service using the configuration file "nginx-controller.yaml", serving on port 8080 and connecting to the containers on port 543200.
Command: ```bash kubectl expose -f nginx-controller.yaml --port=8080 --target-port=543200 ``` 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 ...
Create a new secret named gcp-service-account-secret with keys for each file in the path/to/preferences folder.
Command: ```bash kubectl create secret generic gcp-service-account-secret --from-file=path/to/preferences ``` 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 th...
Apply a taint on nodes with the label 'owner=john-doe' with the key 'hardware' and value 'backup-node-14:PreferNoSchedule'
Command: ```bash kubectl taint node -l owner=john-doe hardware=backup-node-14:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Listen on port 5432 on localhost and IP 10.19.21.23, and forward the traffic to port 8081 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 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 criteri...
Create a cron job named 'data-sync' that runs the command 'java -jar /usr/share/jenkins/jenkins.war' every minute using the image 'jenkins'
Command: ```bash kubectl create cronjob data-sync --image=jenkins --schedule="*/1 * * * *" -- java -jar /usr/share/jenkins/jenkins.war ``` 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"...
Create a service for the wordpress deployment, which serves on port 3306 and connects to the containers on port 30010
Command: ```bash kubectl expose deployment wordpress --port=3306 --target-port=300100 ``` 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...
Add the annotation 'backup-strategy' to the 'email' pod with the value 'daily backups'
Command: ```bash kubectl annotate pods email backup-strategy='daily backups' ``` 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 ...
Forward local traffic on port 8888 to port 8000 in the log-aggregator-pod.
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8888 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...
Import the specific keys 'LOG_LEVEL' from the 'app-config' config map and set them as environment variables in the 'proxy-service-deployment' deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-config deployment/proxy-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Create a new Redis pod named "hazelcast" with the image "redis" and expose port 8080.
Command: ```bash kubectl run hazelcast --image=redis --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...
Copy the contents of /var/run/secrets/kubernetes.io/serviceaccount/ directory from a remote pod named "payment-gateway-pod-19" in the "istio-system" namespace to the local directory "/tmp/bar".
Command: ```bash kubectl cp istio-system/payment-gateway-pod-19:/var/run/secrets/kubernetes.io/serviceaccount/ /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...
Create a new ClusterIP service named inventory-service-clusterip, mapping port 3001 on the service to port 3306 on the target
Command: ```bash kubectl create service clusterip inventory-service-clusterip --tcp=3001:3306 ``` 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": "-...
Import the 'api_key' key from the 'db-config' config map into the 'database-deployment' deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/db-config deployment/database-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 ...
Add a taint with the key 'special' on nodes that have the label 'app-type=microservice'
Command: ```bash kubectl taint node -l app-type=microservice special=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": "", "usa...
Import environment variables from a secret for a deployment
Command: ```bash kubectl set env --from=secret/jwt-secret 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 definitions in one or more pod...
Add a taint with key 'environment' on nodes having label project=project-alpha
Command: ```bash kubectl taint node -l project=project-alpha environment=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": "", "usa...
restart the 'prod' deployment
Command: ```bash kubectl rollout restart deployment/prod ``` What it does: Restart a resource. Resource rollout will be restarted. Syntax: `kubectl rollout restart RESOURCE` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the resource to...
Forward local port 8888 to port 8080 of the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward pod/e-commerce-pod 8888 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...
Set the custom TLS server name to "kube-cluster-1" for the "cluster-gamma" cluster entry
Command: ```bash kubectl config set-cluster cluster-gamma --tls-server-name=kube-cluster-1 ``` 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...
Add a taint with the key 'app' and value 'kube-master-9:PreferNoSchedule' to nodes labeled 'customer=acme-corp'
Command: ```bash kubectl taint node -l customer=acme-corp app=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Create a new config map named app-config with the specified keys from files. The keys are not based on the filenames on disk.
Command: ```bash kubectl create configmap app-config --from-file=conf=/path/to/properties/file1.txt --from-file=data=/path/to/profiles/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a con...
Create a pod named nginx with the image mcr.microsoft.com/dotnet/core/runtime, but override the spec with a partial set of values parsed from the JSON provided.
Command: ```bash kubectl run nginx --image=mcr.microsoft.com/dotnet/core/runtime --overrides='{ "apiVersion": "stable-2.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--override...
Create a cluster role named "view" with the API Group specified for using, getting, and patching resources of type "certificatesigningrequests.certificates.k8s.io"
Command: ```bash kubectl create clusterrole view --verb=use,get,patch --resource=certificatesigningrequests.certificates.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]` Helpfu...
Import the 'secret_key' key from the 'app-config-dev' config map to the 'log-aggregator-deployment' deployment
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-config-dev 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 defin...
Execute the "apache2ctl -D FOREGROUND" command in the first container of the "log-aggregator-deployment" deployment and get the output.
Command: ```bash kubectl exec deploy/log-aggregator-deployment -- 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": "Container n...
Create a new ClusterIP service named monitoring-service-clusterip with a mapping from port 8080 in the service to port 5000 inside the pods
Command: ```bash kubectl create service clusterip monitoring-service-clusterip --tcp=8080:5000 ``` 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": "...
Create a copy of the "proxy-server-pod" with a debug container added and container images changed.
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=my-custom-dbg --image=debian --set-image=scheduler=my-scheduler:1.0,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 r...
Create a new ExternalName service named 'external-git-service' with the external name 'document-company.com'
Command: ```bash kubectl create service externalname external-git-service --external-name document-company.com ``` 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 reference ser...
List deployments in JSON output format, in the "legacy-1.0.0" version of the "external-apps" API group.
Command: ```bash kubectl get deployments.legacy-1.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...
Create a new config map named "app-name-config" with specific keys and file paths
Command: ```bash kubectl create configmap app-name-config --from-file=properties=/path/to/preferences/file1.txt --from-file=key1=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. W...
Attach to the cyber-sleuth container in the analytics-pod to get the output.
Command: ```bash kubectl attach analytics-pod -c cyber-sleuth ``` 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, u...
Update the pod 'monitoring' by adding the annotation 'alert-email' with the value 'alerts@example.com'
Command: ```bash kubectl annotate pods monitoring alert-email=alerts@example.com ``` 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...
Add the taint 'app=db-node-7:PreferNoSchedule' to the nodes with the label 'instance=app-instance-1'
Command: ```bash kubectl taint node -l instance=app-instance-1 app=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"...
Create an ingress called 'private-ingress' that directs requests for site.com/bar to svc1:7000 using a TLS secret named "my-cert"
Command: ```bash kubectl create ingress private-ingress --rule="site.com/bar=svc1:7000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
View the last 53 lines of logs for the pod named email-service-pod
Command: ```bash kubectl logs --tail=53 email-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", "short"...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ directory from the remote pod named logging-agent-pod-7 to the /etc/kubernetes directory on the local machine.
Command: ```bash kubectl cp kubeapps/logging-agent-pod-7:/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": "", "usage...
Import the 'log_level' key from the 'app-settings' config map to 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...
Forward traffic from port 5000 on all addresses to port 6379 in the 'security-service-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 5000:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Create a single ingress called 'api-v2-ingress' that directs requests to website.com/input to the service 'svc1' on port 8089
Command: ```bash kubectl create ingress api-v2-ingress --rule="website.com/input=svc1:8089,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...
Update the 'load-balancer-deployment' deployment by adding a new environment variable SMTP_HOST with the value "smtp.example.com"
Command: ```bash kubectl set env deployment/load-balancer-deployment SMTP_HOST=smtp.example.com ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more po...
Create a job with the command "php --version" using the PHP image.
Command: ```bash kubectl create job scaling-job --image=php -- php --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. O...
Update the pod 'foo' with the label 'unhealthy' and the value 'true'
Command: ```bash kubectl label pods foo unhealthy=true ``` 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...
List the deployments in the "legacy-1.0.0" version of the "backup-apps" API group, displaying the output in JSON format.
Command: ```bash kubectl get deployments.legacy-1.0.0.backup-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...
Create a new ClusterIP service named api-service-clusterip, exposing port 5432 on the cluster IP and forwarding to port 8181 on the service endpoint.
Command: ```bash kubectl create service clusterip api-service-clusterip --tcp=5432:8181 ``` 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", "d...
Update the expiration date annotation of a pod defined in the "settings.json" file.
Command: ```bash kubectl annotate -f settings.json expiration-date='2024-12-31' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and inclu...
Retrieve the previous terminated container logs for the "lunar-launcher" container in the "chat-app-pod" pod.
Command: ```bash kubectl logs -p -c lunar-launcher 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", "...
Retrieve information about the 'email-service-pod' pod in JSON format
Command: ```bash kubectl get -o json pod email-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 you will only se...
Update the label of the pod 'email' to set the 'tier' label to 'database'
Command: ```bash kubectl label pods email tier=database ``` 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": "I...
Create a deployment named "jenkins-x" with the image "ubuntu", and run the command "docker run ubuntu echo "Hello"".
Command: ```bash kubectl create deployment jenkins-x --image=ubuntu -- docker run ubuntu echo "Hello ``` 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": "...
Set the cluster field in a specific context to a specific cluster name
Command: ```bash kubectl config set contexts.edge-context.cluster cluster-alpha ``` 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...
Start a postgres pod and expose port 6379 on the container.
Command: ```bash kubectl run hazelcast --image=postgres --port=6379 ``` 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": "-...
Copy the local directory /tmp/foo_dir_dir to the remote pod ingress-controller-pod-8 in the default namespace, and place it in the directory /etc/kubernetes_dir.
Command: ```bash kubectl cp /tmp/foo_dir_dir ingress-controller-pod-8:/etc/kubernetes_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...
Scale the deployment 'foo' to 3 replicas, matching the current size of 3.
Command: ```bash kubectl scale --current-replicas=3 --replicas=3 deployment/foo ``` 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...
Copy the ~/.config/kube file from a remote pod to your local machine's /tmp/bar directory.
Command: ```bash kubectl cp openfaas/ingress-controller-pod-8:~/.config/kube :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-config-prod deployment/proxy-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Create a single ingress called 'app2-ingress' that directs requests to testing.com/bar to svc1:8080 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="testing.com/bar=svc1:8080,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":...
Retrieve the logs of the previous terminated nano-bot container from the analytics-pod.
Command: ```bash kubectl logs -p -c nano-bot analytics-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short...
Create a ClusterIP service named backend-service-clusterip that listens on port 8010 and forwards traffic to port 5432.
Command: ```bash kubectl create service clusterip backend-service-clusterip --tcp=8010:5432 ``` 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"...
Auto scale the "chat-app" deployment with a minimum of 2 pods and a maximum of 10 pods.
Command: ```bash kubectl autoscale deployment chat-app --min=2 --max=10 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Create a pod disruption budget named notification-service-pdb that selects all pods with the project=my-project label, and ensure that at least one of them is always available.
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=project=my-project --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 --mi...
Start a WordPress pod and configure the container to expose port 8080.
Command: ```bash kubectl run hazelcast --image=wordpress --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": "...
Auto scale the deployment "proxy-server" with a minimum of 7 pods and a maximum of 14 pods.
Command: ```bash kubectl autoscale deployment proxy-server --min=7 --max=14 ``` 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...
Configure the cluster field in the "client-1-context" context to "cluster-alpha"
Command: ```bash kubectl config set contexts.client-1-context.cluster cluster-alpha ``` 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...
Forward traffic from local port 3000 to port 5000 in the 'web-app-pod' pod
Command: ```bash kubectl port-forward pod/web-app-pod 3000 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...