prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create an ingress named 'api-ingress' that routes requests from website.com/example to the service named 'svc1' on port 8082 with a TLS certificate named 'my-cert'.
Command: ```bash kubectl create ingress api-ingress --rule="website.com/example=svc1:8082,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create a cluster role named "admin_role" with permissions to modify specific config maps.
Command: ```bash kubectl create clusterrole admin_role --verb=patch --resource=configmaps --resource-name=notification-service --resource-name=content-delivery ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-...
Update the 'gateway' pod by removing the 'bar' label if it exists
Command: ```bash kubectl label pods gateway role- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If true...
Scale the replica set named 'baz' to 7 replicas.
Command: ```bash kubectl scale --replicas=7 rs/baz ``` 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 validated before...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-settings 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 definiti...
Remove the label 'app' from the 'backend' pod
Command: ```bash kubectl label pods backend app- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If true,...
Update the user field to "cluster-admin" for the "client-1-context" context entry in the Kubernetes configuration.
Command: ```bash kubectl config set-context client-1-context --user=cluster-admin ``` What it does: Set a context entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-context [NAME | --current] [--cluster=cluster_nickn...
Update the 'proxy-server' pod with the annotation 'backup-strategy' and the value 'daily backups'.
Command: ```bash kubectl annotate pods proxy-server 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 i...
Use a specific text editor (in this case "sublime") to edit the configuration of a service
Command: ```bash KUBE_EDITOR="sublime" kubectl edit svc/db-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 custom TLS server name to 'star-cluster' for validation for the 'star-cluster' cluster entry.
Command: ```bash kubectl config set-cluster star-cluster --tls-server-name=star-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] [--certificate...
Create a copy of the 'api-service-pod' pod with the 'debug-image-app' name, and change the command in the 'lunar-launcher' container
Command: ```bash kubectl debug api-service-pod -it --copy-to=debug-image-app --container=lunar-launcher -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used b...
Create a role named "custom_role" with the ability to connect and access pods with the resource names "auth-proxy" and "error-logger"
Command: ```bash kubectl create role custom_role --verb=connect --resource=pods --resource-name=auth-proxy --resource-name=error-logger ``` 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...
Create a cron job named 'email-notifications' that runs the command 'apache2ctl -D FOREGROUND' every minute using the 'wordpress' image.
Command: ```bash kubectl create cronjob email-notifications --image=wordpress --schedule="*/1 * * * *" -- apache2ctl -D FOREGROUND ``` 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": "-...
Edit the docker-registry service using the notepad editor.
Command: ```bash KUBE_EDITOR="notepad" kubectl edit svc/docker-registry ``` 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 variab...
If the current size of the deployment named dev-environment-rs is 1, scale the mysql deployment to 1 replica.
Command: ```bash kubectl scale --current-replicas=1 --replicas=1 deployment/dev-environment-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-...
get deployments in JSON output format for a specific API group and version
Command: ```bash kubectl get deployments.v1.1.1.my-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will on...
Forward local port 8000 to the targetPort of the "https" port in the "logging-service" service, which is running in a selected pod
Command: ```bash kubectl port-forward service/logging-service 8000: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 select...
Create a new config map named app-settings and include the specified keys and values from the provided files.
Command: ```bash kubectl create configmap app-settings --from-file=settings=/path/to/data/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 config ...
Create a pod named 'hazelcast' using the 'amazonlinux' image and set the labels 'app=amazonlinux' and 'env=prod' on the pod and its container.
Command: ```bash kubectl run hazelcast --image=amazonlinux --labels="app=amazonlinux,env=prod" ``` 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 a deployment named mattermost with the golang image
Command: ```bash kubectl create deployment mattermost --image=golang ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml...
Retrieve the logs from all containers in the pod "proxy-server-pod"
Command: ```bash kubectl logs proxy-server-pod --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": "--containe...
Execute the 'dotnet' command in the 'cosmic-container' container within the 'auth-service-pod' pod and retrieve the output.
Command: ```bash kubectl exec auth-service-pod -c cosmic-container -- dotnet ``` 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...
Create a pod disruption budget named elastic-search-pdb that will select all pods with the tier=frontend label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget elastic-search-pdb --selector=tier=frontend --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...
Create a debug copy of api-service-pod with a new container image and changed container images.
Command: ```bash kubectl debug api-service-pod -it --copy-to=debug-image-memcached --image=debian --set-image=app=app:debug,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resou...
Run the 'pip --version' command inside the vpn-service-pod pod and display the output.
Command: ```bash kubectl exec vpn-service-pod -- 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, use the kub...
Update the deployment 'api-server-deployment' by adding a new environment variable
Command: ```bash kubectl set env deployment/api-server-deployment GOOGLE_API_KEY=your-google-api-key ``` 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 mo...
Copy the local kube config file to the /etc/kubernetes directory within a specific container on a remote pod.
Command: ```bash kubectl cp ~/.config/kube monitoring-agent-pod-6:/etc/kubernetes -c monitoring-agent ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name...
Create a pod disruption budget named 'ingress-controller-pdb' that selects all pods with the label 'version=v2'
Command: ```bash kubectl create poddisruptionbudget ingress-controller-pdb --selector=version=v2 --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-availabl...
Create a debug copy of e-commerce-pod by adding a Debian-based debug container and changing the images for the existing containers.
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-memcached --image=debian --set-image=api=api:v2,app=app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and n...
Start a MySQL pod and expose port 8081 for the container.
Command: ```bash kubectl run hazelcast --image=mysql --port=8081 ``` 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...
Execute the 'yum install -y wget' command in the quantum-quark container of the proxy-service-pod pod and print the output.
Command: ```bash kubectl exec proxy-service-pod -c quantum-quark -- 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 role named "reader" with API Group specified and allow the verbs "update", "get" and "patch" on the resource "roles.rbac.authorization.k8s.io"
Command: ```bash kubectl create role reader --verb=update,get,patch --resource=roles.rbac.authorization.k8s.io ``` 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|client|none]` Helpful f...
Expose the replicated python service on port 3001, connecting to the containers on port 8000.
Command: ```bash kubectl expose rs python --port=3001 --target-port=8000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
Update the image of a container in a pod using a JSON patch with positional arrays.
Command: ```bash kubectl patch pod security-service-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]' ``` 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 p...
Add a taint with the key 'zone' and value 'edge-node-10' to all nodes that have the label 'cluster=my-cluster' and set the effect to 'PreferNoSchedule'
Command: ```bash kubectl taint node -l cluster=my-cluster zone=edge-node-10: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 secret named ssh-key-secret with keys for each file in the folder path/to/options.
Command: ```bash kubectl create secret generic ssh-key-secret --from-file=path/to/options ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basename of th...
Forward local ports 8088 and 6000 to ports 8080 and 6000 respectively in a pod selected by the deployment named "notification-handler-deployment"
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 8088 8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Create a cluster role named "bar" with the NonResourceURL specified as `/debug/ns/*`.
Command: ```bash kubectl create clusterrole "bar" --verb=use --non-resource-url=/debug/ns/* ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short"...
Rename the context 'cloud-context' to 'app-2-context'
Command: ```bash kubectl config rename-context cloud-context app-2-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 ...
Create a job named log-processing-job using the golang image and running the command "go"
Command: ```bash kubectl create job log-processing-job --image=golang -- go ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. On...
Add a taint with key 'workload' on nodes having label feature=feature-xyz, specifically on node 'k8s-node-1' with the taint value 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l feature=feature-xyz workload=k8s-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": "", "usag...
Add a taint with the key 'datacenter' and value 'kube-master-9:PreferNoSchedule' on nodes that have the label 'customer=acme-corp'
Command: ```bash kubectl taint node -l customer=acme-corp datacenter=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": "", "...
Execute the "set-last-applied" operation on each configuration file in the "parameters/" directory.
Command: ```bash kubectl apply set-last-applied -f parameters/ ``` What it does: Set the latest last-applied-configuration annotations by setting it to match the contents of a file. This results in the last-applied-configuration being updated as though 'kubectl apply -f ' was run, without updating any other parts of t...
List the replicasets, services, and pods with the names "web", "auth-service-rc", and "web-app-pod"
Command: ```bash kubectl get rc/web service/auth-service-rc pods/web-app-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...
Create a deployment named wordpress using the node image and expose port 7000.
Command: ```bash kubectl create deployment wordpress --image=node --port=7000 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: ...
List the deployments in the "custom-deployments" API group with the version "v1.1.1" in JSON output format
Command: ```bash kubectl get deployments.v1.1.1.custom-deployments -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 an ingress named 'service-ingress' that routes requests from foo.com/example to svc1:8083 with the TLS secret "my-cert"
Command: ```bash kubectl create ingress service-ingress --rule="foo.com/example=svc1:8083,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Partially update the worker-node-3 node by applying the specified YAML patch, which includes adding a new rule for the path "/" with a backend service named new-service.
Command: ```bash kubectl patch node worker-node-3 -p $'spec:\n rules:\n- http:\n paths:\n - path: /\n backend:\n service:\n name: new-service' ``` 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. ...
Add a taint with the key 'disktype' on nodes that have the label tier=frontend
Command: ```bash kubectl taint node -l tier=frontend 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": "...
Create an ingress called 'app2-ingress' with a rule that directs requests to testing.com/example to svc1:8888, with a tls secret called "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="testing.com/example=svc1:8888,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...
Forward ports from local machine to a pod selected by the deployment
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 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 po...
Listen on port 8081 on all addresses and forward the traffic to port 6379 in the pod named 'proxy-server-pod'.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 8081:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/cdn-service-rc pods/web-app-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...
Start a python pod named nginx, but override its spec with a partial set of values parsed from JSON
Command: ```bash kubectl run nginx --image=python --overrides='{ "apiVersion": "v2.1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAN...
Create a new secret named api-secret-key from the environment file located at "path/to/settings.env"
Command: ```bash kubectl create secret generic api-secret-key --from-env-file=path/to/settings.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 basen...
Create a cluster role named "default_role" with the ability to patch services and access the "search-elasticsearch" and "report-generator" resources.
Command: ```bash kubectl create clusterrole default_role --verb=patch --resource=services --resource-name=search-elasticsearch --resource-name=report-generator ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-...
Execute the 'nginx' command in the 'code-explorer' container of the 'frontend-pod' pod and get the output.
Command: ```bash kubectl exec frontend-pod -c code-explorer -- 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 t...
Update the environment variable 'SMTP_USERNAME' for the 'authentication-service-deployment' deployment.
Command: ```bash kubectl set env deployment/authentication-service-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 ...
Import the 'secret_key' key from the 'global-config' config map and set it as an environment variable for the 'payment-processor-deployment' deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/global-config 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 def...
Scale the replica set named 'staging-app-rs' to 1.
Command: ```bash kubectl scale --replicas=1 rs/staging-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 valid...
Forward local port 5000 to port 8888 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward pod/security-service-pod 5000: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 select...
Create a new config map named 'api-config' with the keys 'conf' and 'data' using the specified files '/path/to/settings/file1.txt' and '/path/to/configs/file2.txt' respectively.
Command: ```bash kubectl create configmap api-config --from-file=conf=/path/to/settings/file1.txt --from-file=data=/path/to/configs/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...
Update the label of the pod 'chat-app' to 'release=v1.0'
Command: ```bash kubectl label pods chat-app release=v1.0 ``` 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": ...
Create a job called "data-migration-job" using the nginx image, and execute the command "nginx -t" as part of the job.
Command: ```bash kubectl create job data-migration-job --image=nginx -- nginx -t ``` 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 forma...
forward local ports 8080 to 8088 for a pod named "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-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 auto...
Forward port 3000 on localhost and IP address 10.19.21.23 to port 8081 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-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 criter...
Import the environment variables from the 'ssh-key-secret' secret into the 'scheduler-app-deployment' deployment.
Command: ```bash kubectl set env --from=secret/ssh-key-secret deployment/scheduler-app-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 ...
Create an ingress that maps requests from testing.com/bar to svc1:3000 with the tls secret "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="testing.com/bar=svc1:3000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Rename a context in the kubeconfig file
Command: ```bash kubectl config rename-context local-context 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 ...
Change the CPU and memory limits of the PostgreSQL container in the deployment named "postgres" to "200m" and "1Gi" respectively.
Command: ```bash kubectl set resources deployment postgres -c=nginx --limits=cpu=200m,memory=1Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up t...
Retrieve the snapshot logs from the e-commerce-pod deployment for the scheduler-app-deployment-1 container
Command: ```bash kubectl logs deployment/scheduler-app-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 flags: "f...
Create a Pod Disruption Budget named logging-pdb that will ensure at least one pod with the owner=team-1 label is available at all times.
Command: ```bash kubectl create poddisruptionbudget logging-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 [--dr...
Start a wordpress pod with the name 'nginx' and using the 'wordpress' image
Command: ```bash kubectl run nginx --image=wordpress --overrides='{ "apiVersion": "v1.1.1", "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] -- [COM...
Create an ingress named 'www-ingress' with a rule that directs requests from foo.com/input to svc1:5001
Command: ```bash kubectl create ingress www-ingress --rule="foo.com/input=svc1:5001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Execute the `php --version` command in the `cyber-sleuth` container of the `security-service-pod` pod and retrieve the output.
Command: ```bash kubectl exec security-service-pod -c cyber-sleuth -- php --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...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/log-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 variable...
Import the environment variable from the 'api-key-secret' secret and apply it to the 'analytics-platform-deployment' deployment.
Command: ```bash kubectl set env --from=secret/api-key-secret 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 definitions in one or ...
Copy the local file named "foo" in the "/tmp" directory to the remote pod named "backend-pod-13" in the "/tmp/bar_dir" directory.
Command: ```bash kubectl cp :/tmp/foo kube-server/backend-pod-13:/tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ku...
Autoscale the deployment "database" with a minimum of 2 pods and a maximum of 15 pods.
Command: ```bash kubectl autoscale deployment database --min=2 --max=15 ``` 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...
Update the annotation 'contact-email' of pod 'security' with the value 'support@example.com', replace any existing value
Command: ```bash kubectl annotate --overwrite pods security 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 ...
Forward traffic from port 5000 on localhost and IP 10.19.21.23 to port 8081 in the pod named "mypod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 5000:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a p...
Create a cluster role binding for multiple users and a group using a specified cluster role
Command: ```bash kubectl create clusterrolebinding reader --clusterrole=reader --user=jane.doe --user=bob.smith --group=developers ``` What it does: Create a cluster role binding for a particular cluster role. Syntax: `kubectl create clusterrolebinding NAME --clusterrole=NAME [--user=username] [--group=groupname] [--...
Create a role binding for multiple users and groups using a specific cluster role
Command: ```bash kubectl create rolebinding foo --clusterrole=foo --user=app-operator --user=sysadmin --group=security-auditors ``` What it does: Create a role binding for a particular role or cluster role. Syntax: `kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--group=groupname] [...
Import the "debug_mode" key from the "global-config" config map and set it as an environment variable in the "mydeployment" deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/global-config deployment/mydeployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one ...
Create an ingress called 'private-api-ingress' that directs requests from testing.com/input to svc1:8081, using the tls secret "my-cert"
Command: ```bash kubectl create ingress private-api-ingress --rule="testing.com/input=svc1:8081,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Set the service account of the deployment 'monitoring-stack-deployment' to 'cert-manager'
Command: ```bash kubectl set serviceaccount deployment monitoring-stack-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 Synta...
Get the output of the "ruby --version" command from the first pod of the "monitoring-stack-deployment" deployment.
Command: ```bash kubectl exec deploy/monitoring-stack-deployment -- ruby --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If ...
Partially update a node with the specified type and name from the "node.json" file using strategic merge patch
Command: ```bash kubectl patch -f cni.conf -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 FILE]` Helpful fl...
Forward local port to a pod port
Command: ```bash kubectl port-forward pod/mypod :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 automatically. T...
Create a new secret named jwt-secret by providing a file and a literal value
Command: ```bash kubectl create secret generic jwt-secret --from-file=ssh-privatekey=path/to/id_rsa --from-literal=passphrase=topsecret ``` 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 fi...
Create a new config map named log-config using the parameters from the file located at path/to/parameters.env
Command: ```bash kubectl create configmap log-config --from-env-file=path/to/parameters.env ``` 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 ...
Listen on port 8081 on all addresses and forward the traffic to port 8888 in the 'log-aggregator-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 8081: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 po...
Fetch the snapshot logs from the container 'database-pod-1' of the deployment 'mydeployment'
Command: ```bash kubectl logs deployment/mydeployment -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: "flag": "--conta...
forward the local 5000 port to the deployment selected pod's 3000 port
Command: ```bash kubectl port-forward deployment/mydeployment 5000 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 selecte...
import the value of the 'LOG_LEVEL' key from the 'api-config' config map and set it as an environment variable in the 'gateway-deployment' deployment
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/api-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in on...
Create a copy of the 'e-commerce-pod' with a debug container and updated container images
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=my-debugger --image=debian --set-image=logger=logging-app:debug,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resou...
Start a postgres pod with port 7000 exposed
Command: ```bash kubectl run hazelcast --image=postgres --port=7000 ``` 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": "-...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=max_connections --from=configmap/api-config deployment/scheduler-app-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...
Forward local port 9090 to port 5000 in the notification-handler deployment
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 9090 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Import the 'CONFIG_FILE_PATH' key from the 'app-settings' config map into the 'api-server-deployment' deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --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 defin...