prompt
stringlengths
13
282
response
stringlengths
128
3.11k
import the 'database_url' key from the 'app-name-config' config map and set it as an environment variable in the 'monitoring-stack-deployment' deployment
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-name-config 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 ...
List specific resources by their type and names
Command: ```bash kubectl get rc/web service/cdn-service-rc pods/vpn-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namesp...
Create a job named "testing" using the image "mcr.microsoft.com/dotnet/core/runtime" with the command "dotnet"
Command: ```bash kubectl create job testing --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Set the service account of the deployment "user-management-deployment" to "cert-manager"
Command: ```bash kubectl set serviceaccount deployment user-management-deployment cert-manager ``` 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...
Run a proxy to the Kubernetes API server on port 8080, serving static content from the './local/www/' directory
Command: ```bash kubectl proxy --port=8080 --www=./local/www/ ``` What it does: Creates a proxy server or application-level gateway between localhost and the Kubernetes API server. It also allows serving static content over specified HTTP path. All incoming data enters through one port and gets forwarded to the remote...
Create a new ExternalName service named external-authentication-service with the external name "travel-sample.travel"
Command: ```bash kubectl create service externalname external-authentication-service --external-name travel-sample.travel ``` 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...
Run the 'yum install -y wget' command inside the 'nebula-navigator' container of the 'chat-app-pod', and get the output.
Command: ```bash kubectl exec chat-app-pod -c nebula-navigator -- yum install -y wget ``` 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. ...
Create a pod disruption budget named 'statefulset-pdb' that selects all pods with the 'env=production' label and requires a minimum of 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget statefulset-pdb --selector=env=production --min-available=9 ``` 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 deployment named "registry" that runs the Redis image and exposed port 8000.
Command: ```bash kubectl create deployment registry --image=redis --port=8000 ``` 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: ...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ file from the local machine to /tmp/bar in the 'worker-container' container of the 'front-end-pod-12' pod.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ front-end-pod-12:/tmp/bar -c worker-container ``` 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 a new config map named 'global-config' with the specified keys from the provided files
Command: ```bash kubectl create configmap global-config --from-file=settings=/path/to/configs/file1.txt --from-file=key2=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When crea...
Get the output from running the 'python' command in the lunar-launcher container of the web-app-pod pod
Command: ```bash kubectl exec web-app-pod -c lunar-launcher -- python ``` 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 ...
Create a new NodePort service named my-ns and map port 8082 on the host to port 3306 on the service.
Command: ```bash kubectl create service nodeport my-ns --tcp=3306:8082 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Create a new ClusterIP service named 'security-service-clusterip' with the TCP port mapping from 8000 to 8181.
Command: ```bash kubectl create service clusterip security-service-clusterip --tcp=8000: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...
Import environment variables from the config map named "db-config" into the analytics-platform-deployment
Command: ```bash kubectl set env --from=configmap/db-config --prefix=MYSQL_ 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 definiti...
Forward traffic from port 8081 on your local machine to port 5000 in the web-app-pod pod
Command: ```bash kubectl port-forward pod/web-app-pod 8081: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...
View the details of revision 1 for the daemonset named 'app-v2' by using the command 'kubectl rollout history daemonset/app-v2 --revision=1'
Command: ```bash kubectl rollout history daemonset/app-v2 --revision=1 ``` 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 ...
Create a debug container for media-stream-pod with a different container image
Command: ```bash kubectl debug media-stream-pod -it --copy-to=debug-image-memcached --image=debian --set-image=database=mysql:5.7,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 copy of a specific pod with updated container images to WordPress for debugging purposes.
Command: ```bash kubectl debug cdn-service-pod --copy-to=debug-image-1 --set-image=*=wordpress ``` 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...
Forward local port 3000 to port 8081 in the backend pod, allowing access from localhost and IP address 10.19.21.23
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 3000: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...
Listen on port 8080 locally and forward it to port 8088 in the api-service-pod
Command: ```bash kubectl port-forward pod/api-service-pod 8080: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 au...
Delete pods and services with the names "payment" and "media-stream"
Command: ```bash kubectl delete pod,service payment media-stream ``` 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 sele...
import the environment variables from the global-config config map with the prefix MYSQL_ into the analytics-platform-deployment deployment
Command: ```bash kubectl set env --from=configmap/global-config --prefix=MYSQL_ 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 defi...
Add a taint with the key 'workload' and value 'PreferNoSchedule' on nodes that have the label 'feature=feature-xyz', specifically on the node with the name 'node-2'.
Command: ```bash kubectl taint node -l feature=feature-xyz workload=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": ...
Mark the node "k8s-node-1" as unschedulable
Command: ```bash kubectl cordon k8s-node-1 ``` 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 "
Apply a taint with the key 'app' on all nodes that have the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha 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": ...
Attach to the stardust-shuttle container in the security-service-pod and view its output
Command: ```bash kubectl attach security-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...
Create a service for the 'python' deployment that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment python --port=8010 --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...
Copy the local file /tmp/foo_dir to the remote pod admin-dashboard-pod-16 in the kube-system namespace, and place it at /tmp/bar
Command: ```bash kubectl cp /tmp/foo_dir kube-system/admin-dashboard-pod-16:/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...
Scale the frontend-rs deployment to have 1 replica, if its current size is 7
Command: ```bash kubectl scale --current-replicas=7 --replicas=1 deployment/frontend-rs ``` 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...
Create an ingress called 'public-service-ingress' that directs requests to testing.com/example to svc1:8000 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress public-service-ingress --rule="testing.com/example=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"...
Create an ingress named "ingress1", with multiple hosts and the pathType set as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="website.com/path*=svc:3306" \ --rule="input.com/admin*=svc2:http" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output...
Forward traffic from port 9090 on all addresses to port 8081 in the pod named 'cdn-service-pod'.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 9090: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 w...
Create a new config map named "namespace-config" using the key=value pairs from the file located at "path/to/preferences"
Command: ```bash kubectl create configmap namespace-config --from-file=path/to/preferences ``` 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 b...
Create a deployment named "web" using the "python" image with the specified version.
Command: ```bash kubectl create deployment web --image=python -- python --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. One ...
Begin streaming the logs of the "time-machine" container in the "email-service-pod" pod
Command: ```bash kubectl logs -f -c time-machine 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"...
Create a new ClusterIP service named security-service-clusterip that forwards traffic from port 3001 on the cluster to port 8010 on the service.
Command: ```bash kubectl create service clusterip security-service-clusterip --tcp=3001:8010 ``` 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...
Forward port 5432 from localhost and IP 10.19.21.23 to port 8088 in the pod named "proxy-server-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-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 cr...
Add a taint with key 'disktype' on nodes having label version=v1.0.0
Command: ```bash kubectl taint node -l version=v1.0.0 disktype=gpu-node-12:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Forward port 8000 in the pod "e-commerce-pod" to port 3000 on all addresses and listen for incoming connections.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-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 wi...
Set the custom TLS server name to 'galaxy-cluster' for the cluster entry named 'app-cluster'
Command: ```bash kubectl config set-cluster app-cluster --tls-server-name=galaxy-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificat...
Forward port 6379 on all addresses to port 8088 in the 'mypod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 6379: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 sel...
Update the SMTP_HOST environment variable for the cache-cluster-deployment and output the modified deployment configuration in YAML format, without applying the changes to the server.
Command: ```bash kubectl set env deployment/cache-cluster-deployment SMTP_HOST=smtp.example.com -o yaml ``` 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...
Update the 'load-balancer-deployment' deployment by setting the environment variable LOG_LEVEL to info.
Command: ```bash kubectl set env deployment/load-balancer-deployment LOG_LEVEL=info ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates ...
Copy the local file "foo" located at "/tmp/foo" to the "/etc/kubernetes" directory in the remote pod named "image-resizer-pod-20" and specify that the file should be copied to the "worker-container" container in the pod.
Command: ```bash kubectl cp :/tmp/foo image-resizer-pod-20:/etc/kubernetes -c worker-container ``` 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 om...
Update the environment variables of the 'backend-microservice-deployment' deployment by importing the 'EXTERNAL_API_URL' key from the 'app-settings' config map.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-settings deployment/backend-microservice-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 vari...
Create a new ClusterIP service called "analytics-service-clusterip" that maps port 8082 on the service to port 9090 on the pods.
Command: ```bash kubectl create service clusterip analytics-service-clusterip --tcp=8082:9090 ``` 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": "-...
Set the service account of the deployment "cache-cluster-deployment" to "elasticsearch"
Command: ```bash kubectl set serviceaccount deployment cache-cluster-deployment elasticsearch ``` 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:...
Add a taint with key 'special' on nodes having label version=v1.0.0.
Command: ```bash kubectl taint node -l version=v1.0.0 special=prod-node-5: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, 'settings' and 'key2', using the contents of the files '/path/to/properties/file1.txt' and '/path/to/data/file2.txt' respectively.
Command: ```bash kubectl create configmap app-config --from-file=settings=/path/to/properties/file1.txt --from-file=key2=/path/to/data/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a con...
Set the cluster field in a specific context to a given cluster
Command: ```bash kubectl config set contexts.app-2-context.cluster kube-cluster-1 ``` 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 ...
Update the kube-master-9 node by partially merging the patch specified as YAML, setting the value of the 'someField' field to 'newValue'
Command: ```bash kubectl patch node kube-master-9 -p $'spec:\n someField: newValue' ``` 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]` Helpfu...
Add a taint with key 'workload' on nodes having label 'myLabel' and set the taint value to 'web-node-8:PreferNoSchedule'.
Command: ```bash kubectl taint node -l myLabel workload=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": "", "usage": "Output ...
Create a new config map named `env-vars` and populate it with the data from the specified folder path.
Command: ```bash kubectl create configmap env-vars --from-file=path/to/data ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basename of the ...
Set the resource request and limits for all containers in the "alpine" deployment.
Command: ```bash kubectl set resources deployment alpine --limits=cpu=200m,memory=512Mi --requests=cpu=100m,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 reques...
Import the SECRET_KEY from the app-config-dev ConfigMap into the analytics-platform-deployment deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-config-dev 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 d...
Create a pod named "hazelcast" using the "node" image and configure it to expose port 8000.
Command: ```bash kubectl run hazelcast --image=node --port=8000 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--fil...
Expose a ReplicaSet as a service on port 80, connecting to the containers on port 8000
Command: ```bash kubectl expose rs node --port=80 --target-port=330600 ``` 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...
create a service for the replicated wordpress resources, which serves on port 8443 and connects to the containers on port 909000
Command: ```bash kubectl expose rc wordpress --port=8443 --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 po...
Retrieve the output of running the 'geth' command in the 'quantum-quark' container from the 'api-service-pod' pod.
Command: ```bash kubectl exec api-service-pod -c quantum-quark -- geth ``` 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...
Remove the "client-secret" config value for the OpenID Connect auth provider for the "operator" entry
Command: ```bash kubectl config set-credentials operator --auth-provider=oidc --auth-provider-arg=client-secret- ``` 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-ke...
Set the cluster field in a specific context to a given value
Command: ```bash kubectl config set contexts.cloud-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...
Add a taint with the key 'zone' on nodes having the label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 zone=gpu-node-12:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Out...
Start a node pod named "nginx" with the "node" image, but override the pod spec with a partial set of values parsed from the JSON provided in the overrides parameter.
Command: ```bash kubectl run nginx --image=node --overrides='{ "apiVersion": "dev-2.2.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] -- [COMMA...
Create a pod disruption budget named database-pdb that ensures at least one pod with the owner=team-1 label is always available
Command: ```bash kubectl create poddisruptionbudget database-pdb --selector=owner=team-1 --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 [--d...
Import specific keys from a config map into a deployment environment variable
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-config-dev deployment/backend-microservice-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...
Create a new ClusterIP service named my-cs that forwards traffic from port 3001 to port 3001
Command: ```bash kubectl create service clusterip my-cs --tcp=3001:3001 ``` 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 8888 to port 9090 inside the 'analytics-pod' pod
Command: ```bash kubectl port-forward pod/analytics-pod 8888:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected auto...
Execute the 'mongo' command in the 'cyber-sleuth' container of the 'e-commerce-pod' pod.
Command: ```bash kubectl exec e-commerce-pod -c cyber-sleuth -- mongo ``` 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 local port 6379 to port 9090 in the pod named api-service-pod
Command: ```bash kubectl port-forward pod/api-service-pod 6379: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...
Update the 'load-balancer-deployment' deployment by setting the environment variable SMTP_PASSWORD to 'your-password'
Command: ```bash kubectl set env deployment/load-balancer-deployment SMTP_PASSWORD=your-password ``` 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 p...
Get the output from running the 'node' command in the first container of the first pod of the service 'order-service'.
Command: ```bash kubectl exec svc/order-service -- node ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.ku...
Delete the pods and services named "foo" and "proxy-server"
Command: ```bash kubectl delete pod,service foo proxy-server ``` 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...
Add a taint with key 'zone' on nodes having label role=database.
Command: ```bash kubectl taint node -l role=database zone=storage-node-13: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 the cluster field in the 'service-account-context' context to 'cluster-alpha'
Command: ```bash kubectl config set contexts.service-account-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 v...
Set the custom TLS server name for the testing-cluster cluster entry
Command: ```bash kubectl config set-cluster testing-cluster --tls-server-name=cluster-gamma ``` 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] [--certifi...
Create a copy of the backend-pod by adding a debug container and changing container images
Command: ```bash kubectl debug backend-pod -it --copy-to=debug-image-1 --image=debian --set-image=worker=my-custom-worker:1.2.3,api=api:v2 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource ...
Create an ingress called 'app1-ingress' that directs requests to 'website.com/input' to 'svc1:8088' with a TLS secret called 'my-cert'
Command: ```bash kubectl create ingress app1-ingress --rule="website.com/input=svc1:8088,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Return the snapshot of the previous terminated ruby container logs from the pod named "media-stream-pod".
Command: ```bash kubectl logs -p -c ruby media-stream-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"...
Set the cpu limits to "50m" and memory to "64Mi" for the nginx container in the centos deployment
Command: ```bash kubectl set resources deployment centos -c=nginx --limits=cpu=50m,memory=64Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to ...
Add a taint with key 'workload' on nodes having label cluster=my-cluster
Command: ```bash kubectl taint node -l cluster=my-cluster workload=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": "", "...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/gateway-rc pods/monitoring-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 ...
View the logs from container proxy-service-deployment-1 in the deployment named gateway-pod
Command: ```bash kubectl logs deployment/proxy-service-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: "flag...
Create a new ClusterIP service named api-service-clusterip with port mapping from 9000 to 7000
Command: ```bash kubectl create service clusterip api-service-clusterip --tcp=9000:7000 ``` 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...
Create a new ClusterIP service named auth-service-clusterip that maps port 3000 externally to port 5001 internally
Command: ```bash kubectl create service clusterip auth-service-clusterip --tcp=3000:5001 ``` 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", "...
Edit the 'cache-service' service using the 'nano' text editor.
Command: ```bash KUBE_EDITOR="nano" kubectl edit svc/cache-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, ...
Forward local port 8888 to the 'https' targetPort of the 'search-service' service
Command: ```bash kubectl port-forward service/search-service 8888:https ``` 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 selecte...
Rename the context 'old-name' to 'team-alpha-context' in your kubeconfig file
Command: ```bash kubectl config rename-context old-name team-alpha-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 ...
Expose the replica set for an nginx deployment as a service on port 7000, connecting to the containers on port 8000.
Command: ```bash kubectl expose rs nginx --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 the specified port. ...
Start a pod named 'hazelcast' with the image 'node' and expose port 9092
Command: ```bash kubectl run hazelcast --image=node --port=9092 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--fil...
Create a new config map with specific key-value pairs
Command: ```bash kubectl create configmap api-config --from-literal=settings=config1 --from-literal=key2=config2 ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key...
Remove all the taints with the key 'app' from the node 'testing-node-11'
Command: ```bash kubectl taint nodes testing-node-11 app- ``` 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: json|yaml|n...
Add a taint with the key 'special' on nodes having the label 'component=proxy'
Command: ```bash kubectl taint node -l component=proxy special=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 service named 'ruby' for the replicated pods, which will serve traffic on port 8080 and connect to the containers on port 808100
Command: ```bash kubectl expose rc ruby --port=8080 --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 specified port. A...
Retrieve the snapshot logs from the container named vpn-service-pod-1 in the deployment named analytics-platform-deployment.
Command: ```bash kubectl logs deployment/analytics-platform-deployment -c vpn-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 fla...
Retrieve the snapshot logs from the container authentication-service-deployment-1 of the deployment named e-commerce-pod
Command: ```bash kubectl logs deployment/authentication-service-deployment -c e-commerce-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 ...
Execute the 'go version' command inside the first pod of the 'monitoring-stack-deployment' deployment
Command: ```bash kubectl exec deploy/monitoring-stack-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 omit...
Import specific keys from a config map by setting environment variables in a deployment
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-secrets deployment/payment-processor-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 ...
Create a new NodePort service named 'ingress-controller-nodeport' that maps TCP port 8888 on the host to TCP port 3000 on the pods.
Command: ```bash kubectl create service nodeport ingress-controller-nodeport --tcp=8888:3000 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "de...
Update the pod 'web' with the annotation 'contact-email' and set its value as support@example.com
Command: ```bash kubectl annotate pods web contact-email=support@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 include ...