prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Import only the "SMTP_SERVER" key from the "app-config-prod" config map and set it as an environment variable in the "log-aggregator-deployment" deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-config-prod 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 def...
Execute the 'python --version' command in the astro-container within the frontend-pod and display the output
Command: ```bash kubectl exec frontend-pod -c astro-container -- python --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Create a pod named 'hazelcast' using the 'node' image, and expose port 8443.
Command: ```bash kubectl run hazelcast --image=node --port=8443 ``` 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...
Start a pod called "hazelcast" using the image "mcr.microsoft.com/dotnet/core/runtime" and configure the container to expose port 3000.
Command: ```bash kubectl run hazelcast --image=mcr.microsoft.com/dotnet/core/runtime --port=3000 ``` 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......
Create an ingress called 'app-ingress' with a rule that directs requests from testing.com/input to svc1:6379
Command: ```bash kubectl create ingress app-ingress --rule="testing.com/input=svc1:6379,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"...
Forward port 8888 in the pod 'frontend-pod' to port 9090 on all addresses (0.0.0.0).
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 9090: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...
Create a new secret named ssh-key-secret from the preferences.env file located at path/to/preferences.env
Command: ```bash kubectl create secret generic ssh-key-secret --from-env-file=path/to/preferences.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 ba...
Import specific keys from a config map to a deployment's environment variables
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/env-vars 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 one or more ...
Set resource requests and limits for containers in deployment named python.
Command: ```bash kubectl set resources deployment python --limits=cpu=200m,memory=512Mi --requests=cpu=3,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,...
Create a role named "admin_role" with specific resource names
Command: ```bash kubectl create role admin_role --verb=use --resource=pods --resource-name=cdn-proxy --resource-name=queue-consumer ``` 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=server|cli...
Update a node with a new password using a patch file and strategic merge patch
Command: ```bash kubectl patch -f node-specific.yaml -p '{"stringData":{"password":"new-password"}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-fil...
Create a service for the replicated node with the name 'node' to serve on port 80 and connect to the containers on port 8000
Command: ```bash kubectl expose rc node --port=80 --target-port=844300 ``` 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 Pod Disruption Budget with the name 'replica-set-pdb' that selects all pods with the label 'role=worker' and requires at least 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget replica-set-pdb --selector=role=worker --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 [-...
Partially update the node specified in "machine-configuration.yaml" using the provided strategic merge patch
Command: ```bash kubectl patch -f machine-configuration.yaml -p '{"spec":{"type":"LoadBalancer"}' ``` 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 ...
Forward traffic from port 8000 on localhost and IP 10.19.21.23 to port 3000 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8000: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 crite...
Create a new ClusterIP service named shipping-service-clusterip that maps port 8181 on the service to port 9091 on the pods
Command: ```bash kubectl create service clusterip shipping-service-clusterip --tcp=8181:9091 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o...
Create an ingress called 'app-proxy-ingress' that directs requests from foo.com/example to the service 'svc1' on port 8443
Command: ```bash kubectl create ingress app-proxy-ingress --rule="foo.com/example=svc1:8443,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Update the pod 'auth' with the annotation 'backup-strategy' and the value 'daily-backups', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods auth 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 a...
Execute the 'jenkins-plugin-cli' command in the media-stream-pod and retrieve the output from the first container
Command: ```bash kubectl exec media-stream-pod -- jenkins-plugin-cli ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Delete the pods and services named "proxy-server" and "auth".
Command: ```bash kubectl delete pod,service proxy-server auth ``` 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 selecto...
Create a secret from files in a folder
Command: ```bash kubectl create secret generic encryption-key-secret --from-file=path/to/properties ``` 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 base...
Set the cluster field in the my-context context to cluster-gamma
Command: ```bash kubectl config set contexts.client-1-context.cluster cluster-gamma ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value yo...
Create a role named "reader" with the following permissions: update access to pods and specific resource names "report-generator" and "keycloak-server"
Command: ```bash kubectl create role reader --verb=update --resource=pods --resource-name=report-generator --resource-name=keycloak-server ``` 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=ser...
Rename a context in your kubeconfig file
Command: ```bash kubectl config rename-context dev-context team-beta-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 als...
Remove all taints with key 'datacenter' from node 'node-1'
Command: ```bash kubectl taint nodes node-1 datacenter- ``` 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|nam...
Create an ingress called 'public-service-ingress' that directs requests from testing.com/module to svc1:5001 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress public-service-ingress --rule="testing.com/module=svc1:5001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default":...
Copy the `/var/run/secrets/kubernetes.io/serviceaccount/` directory from the `istio-system/database-pod-2` pod to the `/tmp/bar` directory on the local machine.
Command: ```bash kubectl cp istio-system/database-pod-2:/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": "Con...
Create an ingress resource with TLS enabled using a specific secret and pathType set as Prefix.
Command: ```bash kubectl create ingress ingsecret --class=default \ --rule="testing.com/*=svc:8080,tls=secret1" ``` 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": ...
Set the cluster field in the 'my-context' context to 'data-cluster'
Command: ```bash kubectl config set contexts.user-b-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...
Update the pod named 'vpn' by adding the annotation 'monitoring-tool' with the value 'Prometheus', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods vpn monitoring-tool='Prometheus' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and i...
Embed the certificate authority data for the "galaxy-cluster" cluster entry
Command: ```bash kubectl config set-cluster galaxy-cluster --embed-certs --certificate-authority=~/.kube/sun-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config se...
scale replica set to 7 replicas
Command: ```bash kubectl scale --replicas=7 rs/prod-app-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 is specified, it is validate...
Set a custom TLS server name for the prod-cluster cluster entry to be used for validation.
Command: ```bash kubectl config set-cluster prod-cluster --tls-server-name=cluster-alpha ``` 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...
Retrieve the replication controller 'web', the service 'web-app-rc', and the pod 'proxy-service-pod'
Command: ```bash kubectl get rc/web service/web-app-rc pods/proxy-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 namespac...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ file from the local machine to the /etc/kubernetes directory in the admin-dashboard-pod-16 pod in the kube-server namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ kube-server/admin-dashboard-pod-16:/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": "", ...
Import specific keys from a config map to a deployment's environment variables.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/env-vars deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Start listening on port 8000 locally and forward data to/from port 6379 in the pod named "mypod".
Command: ```bash kubectl port-forward pod/mypod 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 automaticall...
Create a new configmap named api-config with specified keys from files on disk
Command: ```bash kubectl create configmap api-config --from-file=conf=/path/to/profiles/file1.txt --from-file=data=/path/to/settings/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 confi...
Import specific keys from a config map into the deployment's environment variables.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-settings deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions ...
Create a copy of the 'auth-service-pod' and change all container images to 'python'
Command: ```bash kubectl debug auth-service-pod --copy-to=my-debugger --set-image=*=python ``` 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 res...
Listen on port 8081 locally, forwarding to port 8080 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 8081:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
List the specified resources by their type and names.
Command: ```bash kubectl get rc/web service/backend-rc pods/auth-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 namespace...
Forward the http trafic to the 'https' port of the 'user-service' service to the local port 5000
Command: ```bash kubectl port-forward service/user-service 5000: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 selected ...
Delete the pods and services named "api" and "proxy-server"
Command: ```bash kubectl delete pod,service api 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...
Update the pod 'auth' by adding or modifying the annotation 'env' with the value 'staging'.
Command: ```bash kubectl annotate --overwrite pods auth env='staging' ``` 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 arbitra...
Attach to a running pod and access the container shell in interactive mode.
Command: ```bash kubectl attach cdn-service-pod -c cosmic-container -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. I...
Create a cron job named 'cleanup-task' using the 'redis' image
Command: ```bash kubectl create cronjob cleanup-task --image=redis --schedule="*/1 * * * *" -- redis-cli ``` 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", "...
Output the modified deployment in YAML without altering the object on the server
Command: ```bash kubectl set env deployment/user-management-deployment SECRET_KEY=your-secret-key -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 ...
Update the pod 'email' by removing a specific label
Command: ```bash kubectl label pods email release- ``` 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 tru...
Create a deployment named 'logging' using the 'python' image and expose port 8010.
Command: ```bash kubectl create deployment logging --image=python --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 of: ...
Create a new config map named 'log-config' using the files 'file1.txt' and 'file2.txt' as values for keys 'conf' and 'data' respectively.
Command: ```bash kubectl create configmap log-config --from-file=conf=/path/to/parameters/file1.txt --from-file=data=/path/to/data/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config ...
forward local traffic from port 8081 to the selected pod's port 8081 and from port 6000 to the selected pod's port 6000 in the notification-handler-deployment deployment
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 8081 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 ...
Retrieve the logs of the previous terminated cyber-sleuth container from the frontend-pod pod.
Command: ```bash kubectl logs -p -c cyber-sleuth frontend-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "sh...
create a new ingress called 'internal-ingress' with a rule that directs requests from 'site.com/example' to the service 'svc1' on port 8010, using the TLS secret 'my-cert'
Command: ```bash kubectl create ingress internal-ingress --rule="site.com/example=svc1:8010,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
create a cron job named "metrics-collection" that runs the command "ruby --version" every minute using the ruby image.
Command: ```bash kubectl create cronjob metrics-collection --image=ruby --schedule="*/1 * * * *" -- ruby --version ``` 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...
Create a cluster role named "reader" with the ability to update the pods and specific resource names.
Command: ```bash kubectl create clusterrole reader --verb=update --resource=pods --resource-name=identity-provider --resource-name=error-logger ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|clien...
Retrieve the output of the 'pip --version' command running inside the warp-drive container of the analytics-pod
Command: ```bash kubectl exec analytics-pod -c warp-drive -- 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. If omitted,...
Create a MySQL pod named "hazelcast" using the mysql image and expose port 5000 for communication.
Command: ```bash kubectl run hazelcast --image=mysql --port=5000 ``` 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...
Update the 'analytics-platform-deployment' deployment by adding a new environment variable 'SMTP_USERNAME' with the value 'your-username'
Command: ```bash kubectl set env deployment/analytics-platform-deployment SMTP_USERNAME=your-username ``` 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 m...
Check if the current user has permission to list the job named "batch-processing-job" in the "kube-ingress" namespace
Command: ```bash kubectl auth can-i list jobs.batch/batch-processing-job -n kube-ingress ``` 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 part...
Create a role named "view" with the following permissions:
Command: ```bash kubectl create role view --verb=patch --resource=pods --resource-name=content-delivery --resource-name=cache-redis ``` 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=server|cli...
Create a job named 'backup' using the 'ruby' image, and run the 'irb' command inside the job.
Command: ```bash kubectl create job backup --image=ruby -- irb ``` 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: json|ya...
delete the pods and services with names "payment" and "gateway"
Command: ```bash kubectl delete pod,service payment gateway ``` 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 'cpu-type' and no value to the node 'prod-node-5'
Command: ```bash kubectl taint nodes prod-node-5 cpu-type:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: ...
Return the previous terminated lunar-launcher container logs from the pod email-service-pod
Command: ```bash kubectl logs -p -c lunar-launcher 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": "--containe...
Copy the file "/tmp/foo" from the remote pod "kube-system/payment-gateway-pod-19" to "/tmp/bar" locally
Command: ```bash kubectl cp kube-system/payment-gateway-pod-19:/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 service for the 'node' deployment, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose deployment node --port=8000 --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 specified...
Update the label "status" of a pod to "unhealthy" based on the configuration file "pod.json"
Command: ```bash kubectl label -f pod.json status=unhealthy ``` 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"...
Execute the 'mysqld' command in the first container of the 'mydeployment' deployment.
Command: ```bash kubectl exec deploy/mydeployment -- mysqld ``` 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 kubect...
Port forward from local ports 5432 and 6000 to ports 8080 and 6000 respectively in the selected pod from the search-engine-deployment.
Command: ```bash kubectl port-forward deployment/search-engine-deployment 5432 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 wil...
Run the 'elasticsearch --version' command in the first pod of the backend-service, using the default container
Command: ```bash kubectl exec svc/backend-service -- elasticsearch --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 omitte...
Set the service account of the mydeployment deployment to fluentd
Command: ```bash kubectl set serviceaccount deployment mydeployment fluentd ``` 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: `kubectl set serv...
View the list of supported API resources, sorted by a specific column.
Command: ```bash kubectl api-resources --sort-by=storageVersionHash ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Import the 'config_file_path' key from the 'app-config-dev' config map into the 'proxy-service-deployment' deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-config-dev 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 ...
Forward traffic from local port 8080 to port 8000 in a pod selected by the deployment named "monitoring-stack-deployment".
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 8080 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 ...
Copy the local file "/tmp/foo_dir" to the remote pod "istio-system/auth-service-pod-11" in the "/tmp/bar" directory in the specified namespace.
Command: ```bash kubectl cp /tmp/foo_dir istio-system/auth-service-pod-11:/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 t...
Set the service account of the 'monitoring-stack-deployment' deployment to 'kube-controller-manager'
Command: ```bash kubectl set serviceaccount deployment monitoring-stack-deployment kube-controller-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), statefu...
Import the environment variables from the oauth-secret secret and apply them to the gateway-deployment deployment.
Command: ```bash kubectl set env --from=secret/oauth-secret deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod temp...
Import the SMTP_SERVER key from the namespace-config ConfigMap and set it as an environment variable in the analytics-platform-deployment deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/namespace-config deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variabl...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/media-stream-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 names...
Run the 'mongo' command in the 'warp-drive' container inside the 'email-service-pod' pod and get the output
Command: ```bash kubectl exec email-service-pod -c warp-drive -- 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...
create a new ClusterIP service named log-service-clusterip with port mapping from 8088 to 9091
Command: ```bash kubectl create service clusterip log-service-clusterip --tcp=8088:9091 ``` 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...
Add a taint with key 'environment' on nodes having label app=web-app
Command: ```bash kubectl taint node -l app=web-app environment=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 pod named 'hazelcast' using the 'mysql' image and expose port 27017
Command: ```bash kubectl run hazelcast --image=mysql --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": "--f...
Create an ingress named 'api-v1-ingress' that redirects requests from website.com/example to svc1:8181 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress api-v1-ingress --rule="website.com/example=svc1:8181,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Forward traffic from port 8088 on all addresses to port 5432 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 8088:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Set the CPU limits of the nginx container in the centos deployment to 50m and the memory limits to 256Mi.
Command: ```bash kubectl set resources deployment centos -c=nginx --limits=cpu=50m,memory=256Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to...
List the supported API resources for the specified API group.
Command: ```bash kubectl api-resources --api-group=node.k8s.io ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Create a job named "deployment-rollout-job" using the "php" image, and execute the command "php --version" within the job.
Command: ```bash kubectl create job deployment-rollout-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": "Outpu...
Create a single ingress named 'app-proxy-ingress' with a rule that directs requests made to 'site.com/input' to the service 'svc1' on port 8000
Command: ```bash kubectl create ingress app-proxy-ingress --rule="site.com/input=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": "", "usa...
Create an ingress called 'app-loadbalancer-ingress' that directs requests to website.com/bar to svc1:5000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="website.com/bar=svc1:5000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ...
Update the pod named 'vpn' with the label 'component' and set its value to 'web'.
Command: ```bash kubectl label pods vpn component=web ``` 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 ...
Add a taint with the key 'dedicated' on nodes having the label 'instance=app-instance-1'
Command: ```bash kubectl taint node -l instance=app-instance-1 dedicated=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": "", ...
Mark the node "testing-node-11" as schedulable
Command: ```bash kubectl uncordon testing-node-11 ``` What it does: Mark node as schedulable. Syntax: `kubectl uncordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Check if you have permission to list the "log-rotation-job" job in the "default" namespace
Command: ```bash kubectl auth can-i list jobs.batch/log-rotation-job -n default ``` 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 URL t...
Retrieve and display the deployments in the "beta-1.0" version of the "mobile-apps" API group in YAML format.
Command: ```bash kubectl get deployments.beta-1.0.mobile-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you w...
Create a new ingress called 'app-loadbalancer-ingress' with a rule that directs requests from testing.com/module to the 'svc1' service on port 8000
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="testing.com/module=svc1:8000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default...
Open the 'api-service' service for editing using the 'sublime' editor.
Command: ```bash KUBE_EDITOR="sublime" kubectl edit svc/api-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,...
Set the resource request and limits for all containers in the `hazelcast` deployment
Command: ```bash kubectl set resources deployment hazelcast --limits=cpu=200m,memory=512Mi --requests=cpu=2,memory=512Mi ``` 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 reque...
Forward local port 8088 to port 3000 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward pod/cdn-service-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 au...