prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Execute the command 'npm --version' inside the 'nano-bot' container of the 'log-aggregator-pod' pod and retrieve the output.
Command: ```bash kubectl exec log-aggregator-pod -c nano-bot -- npm --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitt...
Set the annotation 'SLA' with the value '99.9% uptime' on the pod 'foo'
Command: ```bash kubectl annotate pods foo SLA='99.9% uptime' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitrary strin...
Listen on port 3000 locally, forwarding data to/from port 6379 in the pod selected by the 'api-server-deployment' deployment.
Command: ```bash kubectl port-forward deployment/api-server-deployment 3000 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 b...
Create a new secret named gcp-service-account-secret from the configurations.env file located at path/to/configurations.env
Command: ```bash kubectl create secret generic gcp-service-account-secret --from-env-file=path/to/configurations.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 de...
Update the 'notification-handler-deployment' deployment by adding a new environment variable 'REDIS_HOST' with the value 'redis-server'.
Command: ```bash kubectl set env deployment/notification-handler-deployment REDIS_HOST=redis-server ``` 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 mor...
Create an ingress called 'public-service-ingress' that routes requests from website.com/module to svc1:7000 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress public-service-ingress --rule="website.com/module=svc1:7000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default":...
Copy a directory from a remote pod to your local machine
Command: ```bash kubectl cp kube-public/load-balancer-pod-9:/tmp/foo_dir :/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...
Update the compliance level of a pod defined in the "setup.json" file
Command: ```bash kubectl annotate -f setup.json compliance-level=PCI-DSS ``` 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 arbi...
Create a secret named tls-certificate-secret from an environment file
Command: ```bash kubectl create secret generic tls-certificate-secret --from-env-file=path/to/data.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 b...
Create a job named 'image-build-job', using the 'ruby' image, and run the command 'ruby --version'
Command: ```bash kubectl create job image-build-job --image=ruby -- ruby --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output for...
Create a cluster role named "custom_role" with specified resource names for "configmaps", "blog-backend" and "image-processor"
Command: ```bash kubectl create clusterrole custom_role --verb=watch --resource=configmaps --resource-name=blog-backend --resource-name=image-processor ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=serv...
Execute the 'elasticsearch' command in the 'stardust-shuttle' container of the 'payment-gateway-pod' pod and retrieve the output.
Command: ```bash kubectl exec payment-gateway-pod -c stardust-shuttle -- elasticsearch ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name....
Create a copy of the "api-service-pod" pod and add a debug container to it with the image "busybox"
Command: ```bash kubectl debug api-service-pod -it --image=busybox --copy-to=debug-image-memcached ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default i...
Copy the contents of the "/var/run/secrets/kubernetes.io/serviceaccount/" directory from the "admin-dashboard-pod-16" pod to the local "/etc/kubernetes" directory.
Command: ```bash kubectl cp kube-dns/admin-dashboard-pod-16:/var/run/secrets/kubernetes.io/serviceaccount/ /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "us...
Forward local port 8081 to port 8888 in the frontend-pod
Command: ```bash kubectl port-forward pod/frontend-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 pod will be selected autom...
Set the basic authentication credentials for the "jane.smith" entry with the username as "admin" and the password as "uXFGweU9l35qcif".
Command: ```bash kubectl config set-credentials jane.smith --username=admin --password=uXFGweU9l35qcif ``` 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-key=keyfile ...
Setup local port forwarding to access a pod's ports remotely
Command: ```bash kubectl port-forward pod/proxy-server-pod 8081 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 be selected a...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-settings deployment/user-management-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...
Set the CPU and memory limits for the centos container in the deployment named centos
Command: ```bash kubectl set resources deployment centos -c=nginx --limits=cpu=200m,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to ...
Update the pod identified by the type and name specified in the "conf.json" file
Command: ```bash kubectl annotate -f conf.json compliance-level=PCI-DSS ``` 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 arbit...
Import specific keys from a config map into an environment variable for a deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-settings 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...
Output the modified YAML for a deployment without affecting the deployment on the server.
Command: ```bash kubectl set env deployment/frontend-deployment REDIS_HOST=redis-server -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 more po...
Auto scale the replication controller "cdn" with the number of pods between 1 and 7, based on the target CPU utilization of 50%.
Command: ```bash kubectl autoscale rc cdn --max=7 --cpu-percent=50 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Attach to the 'warp-drive' container in the 'gateway-pod' pod and switch to raw terminal mode, allowing you to interact with the bash shell.
Command: ```bash kubectl attach gateway-pod -c warp-drive -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Create a new pod called hazelcast using the golang image, and configure the container to expose port 3001.
Command: ```bash kubectl run hazelcast --image=golang --port=3001 ``` 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 a new config map named app-name-config with the specified keys and files
Command: ```bash kubectl create configmap app-name-config --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When...
Create a service for a PHP deployment, serving on port 9090 and connecting to the containers on port 8000.
Command: ```bash kubectl expose deployment php --port=9090 --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 po...
Set the custom TLS server name to use for validation for the kube-cluster-1 cluster entry
Command: ```bash kubectl config set-cluster kube-cluster-1 --tls-server-name=moon-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] [--certifica...
Forward traffic from local port 6379 to the pod's port 9090
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 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 sel...
Create a service named "frontend" exposing the pod "proxy-server-pod" on port 3001.
Command: ```bash kubectl expose pod proxy-server-pod --port=3001 --name=frontend ``` 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...
Execute the 'mysqld' command inside the 'database-pod' pod to get the output
Command: ```bash kubectl exec database-pod -- 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 kubectl.kuber...
Embed the certificate authority data for the star-cluster cluster entry.
Command: ```bash kubectl config set-cluster star-cluster --embed-certs --certificate-authority=~/.kube/edge-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 set...
Forward local port 8088 to port 8000 in the pod named 'mypod'
Command: ```bash kubectl port-forward pod/mypod 8088:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Remove the taint with key 'zone' and effect 'PreferNoSchedule' from the 'prod-node-5' node if one exists
Command: ```bash kubectl taint nodes prod-node-5 zone: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 format. One o...
Create a new ClusterIP service named payment-service-clusterip
Command: ```bash kubectl create service clusterip payment-service-clusterip --tcp=9090: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"...
Import the 'redis_host' key from the 'log-config' ConfigMap and set it as an environment variable for the 'email-server-deployment' deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/log-config deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Import the specific key 'EXTERNAL_API_URL' from the config map 'kube-system-config' into the deployment 'gateway-deployment' using the `kubectl set env` command.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/kube-system-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 de...
Import environment variables with a prefix from the 'app-secrets' config map into the 'frontend-deployment' deployment
Command: ```bash kubectl set env --from=configmap/app-secrets --prefix=MYSQL_ deployment/frontend-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 o...
Forward port 8081 on your local machine to port 5432 in the pod named 'log-aggregator-pod'
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8081: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 be selected...
Create a pod disruption budget named load-balancer-pdb that selects pods with the component=web label and requires at least 9 of them to be available at any given time.
Command: ```bash kubectl create poddisruptionbudget load-balancer-pdb --selector=component=web --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=...
Set the service account of the deployment named "gateway-deployment" to "tiller".
Command: ```bash kubectl set serviceaccount deployment gateway-deployment tiller ``` 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...
Create a new ClusterIP service named 'messaging-service-clusterip' that maps the local port 9091 to the target port 5432.
Command: ```bash kubectl create service clusterip messaging-service-clusterip --tcp=9091:5432 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-...
Add a taint to node 'kube-master-9' with the key 'disktype' and no value
Command: ```bash kubectl taint nodes kube-master-9 disktype: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...
Set the cluster field in the specified context to the desired cluster name.
Command: ```bash kubectl config set contexts.user-a-context.cluster galaxy-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you...
Edit service monitoring-service using vim as the editor
Command: ```bash KUBE_EDITOR="vim" kubectl edit svc/monitoring-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 variabl...
Create an ingress called 'private-api-ingress' with a rule that directs requests to 'testing.com/module' to the service 'svc1' on port '3306'
Command: ```bash kubectl create ingress private-api-ingress --rule="testing.com/module=svc1:3306,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ""...
Retrieve the previous terminated logs of the quantum-quark container from the analytics-pod.
Command: ```bash kubectl logs -p -c quantum-quark analytics-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "...
Port-forward traffic from local port 8888 to port 8088 in the pod named 'chat-app-pod'
Command: ```bash kubectl port-forward pod/chat-app-pod 8888: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 autom...
Forward traffic from port 5432 to port 8080 in the pod "api-service-pod" and listen on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 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 w...
Set the resource request and limits for all containers in the php deployment
Command: ```bash kubectl set resources deployment php --limits=cpu=200m,memory=512Mi --requests=cpu=500m,memory=256Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requeste...
Create a job with a specific command
Command: ```bash kubectl create job batch-processing --image=postgres -- postgres ``` 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 form...
Create a job that runs a command in a container using the specified image
Command: ```bash kubectl create job security-scan-job --image=wordpress -- apache2ctl -D FOREGROUND ``` 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...
Create an ingress named 'web-ingress' that directs requests from "website.com/example" to "svc1:8888" with the TLS secret "my-cert".
Command: ```bash kubectl create ingress web-ingress --rule="website.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": "", "usag...
Retrieve the list of deployments in the "v2.1.0" version of the "external-apps" API group, and display them in YAML format.
Command: ```bash kubectl get deployments.v2.1.0.external-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...
Copy the file /tmp/foo from the remote pod argocd/auth-service-pod-11 to /tmp/bar on your local machine
Command: ```bash kubectl cp argocd/auth-service-pod-11:/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 kubectl...
Start a pod named 'hazelcast' using the 'nginx' image and expose port 8443 in the container
Command: ```bash kubectl run hazelcast --image=nginx --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": "--fi...
Create a debug container in a pod by copying an existing pod and changing container images
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-memcached --image=debian --set-image=logger=logging-app:debug,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...
Update the label of the pod named 'frontend' to have the key 'status' with the value 'unhealthy', even if there is an existing value.
Command: ```bash kubectl label --overwrite pods frontend 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": "f...
Begin streaming the logs of the ruby container in the analytics-pod
Command: ```bash kubectl logs -f -c ruby analytics-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "...
Import the "database_url" key from the "app-secrets" config map into the "web-app-deployment" deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-secrets deployment/web-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 i...
Scale the mysql deployment to 1 replica if the current size of the webapp-replicaset deployment is 7.
Command: ```bash kubectl scale --current-replicas=7 --replicas=1 deployment/webapp-replicaset ``` 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-v...
Copy the contents of /var/run/secrets/kubernetes.io/serviceaccount/ from the 'payment-gateway-pod-19' pod in the 'cert-manager' namespace to the /tmp/bar directory on your local machine.
Command: ```bash kubectl cp cert-manager/payment-gateway-pod-19:/var/run/secrets/kubernetes.io/serviceaccount/ /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage...
Create a pod disruption budget named auth-service-pdb that selects all pods with the tier=frontend label and requires a minimum of four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget auth-service-pdb --selector=tier=frontend --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N...
Create a new ExternalName service named 'my-ns' with the externalName 'placeholder-app.app'
Command: ```bash kubectl create service externalname my-ns --external-name placeholder-app.app ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference services that exist...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-settings 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 definiti...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ local file to /tmp/bar directory in the remote pod named admin-dashboard-pod-16 in the kube-public namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ kube-public/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"...
Autoscale a deployment "foo" with a minimum of 4 pods and a maximum of 9 pods.
Command: ```bash kubectl autoscale deployment foo --min=4 --max=9 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the ...
Delete pods and services with the label release=beta
Command: ```bash kubectl delete pods,services -l release=beta ``` 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...
Forward local port 8888 to port 9090 in a pod named "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-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 au...
Forward local ports 5000 and 6000 to the corresponding ports in a selected pod of the deployment "search-engine-deployment"
Command: ```bash kubectl port-forward deployment/search-engine-deployment 5000 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Create a service for the ruby deployment that serves on port 8010 and connects to the containers on port 637900
Command: ```bash kubectl expose deployment ruby --port=8010 --target-port=637900 ``` 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...
Create a new ExternalName service named external-identity-provider-service for the domain demo-service.dev
Command: ```bash kubectl create service externalname external-identity-provider-service --external-name demo-service.dev ``` 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 ref...
Retrieve the snapshot logs from the container named security-service-pod-1 in the deployment named frontend-deployment.
Command: ```bash kubectl logs deployment/frontend-deployment -c security-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "...
Embed the certificate authority data for the 'prod-cluster' cluster entry using the command 'kubectl config set-cluster prod-cluster --embed-certs --certificate-authority=~/.kube/moon-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster prod-cluster --embed-certs --certificate-authority=~/.kube/moon-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 set...
Create a new ClusterIP service named git-service-clusterip with port mapping from 8010 to 8084
Command: ```bash kubectl create service clusterip git-service-clusterip --tcp=8010:8084 ``` 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...
Copy the local file /tmp/foo to the /tmp/bar directory in a specific container (message-broker) of the remote pod (task-processor-pod-17).
Command: ```bash kubectl cp /tmp/foo task-processor-pod-17:/tmp/bar -c message-broker ``` 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, us...
Create a job named "cleanup" using the MySQL image and run the command "mysql --version" inside the job.
Command: ```bash kubectl create job cleanup --image=mysql -- mysql --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. O...
Update the environment variable 'DB_USER' for the deployment 'authentication-service-deployment'.
Command: ```bash kubectl set env deployment/authentication-service-deployment DB_USER=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 more pod...
Set the service account of the search-engine-deployment deployment to "tiller"
Command: ```bash kubectl set serviceaccount deployment search-engine-deployment tiller ``` 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: `kubec...
Forward local traffic on port 9090 to port 8888 in the pod named proxy-server-pod
Command: ```bash kubectl port-forward pod/proxy-server-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 be selected a...
Create an ingress called 'private-service-ingress' that routes requests to website.com/input to svc1:8084 with the tls secret "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="website.com/input=svc1:8084,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default":...
Create a pod disruption budget named 'messaging-pdb' that will select all pods with the 'version=v2' label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=version=v2 --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...
delete all pods and services with the label environment=production
Command: ```bash kubectl delete pods,services -l environment=production ``` 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 lab...
Edit the service "web-service" using the micro editor as an alternative editor.
Command: ```bash KUBE_EDITOR="micro" kubectl edit svc/web-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, o...
Import the MAX_CONNECTIONS key from the ui-config config map into the gateway-deployment deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/ui-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 ...
Create a single ingress called 'public-service-ingress' that directs requests to site.com/bar to svc1:5000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress public-service-ingress --rule="site.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": "", "...
Embed the certificate authority data for the on-prem-cluster cluster entry
Command: ```bash kubectl config set-cluster on-prem-cluster --embed-certs --certificate-authority=~/.kube/cloud-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...
Create a new secret from an environment file
Command: ```bash kubectl create secret generic ssl-key-secret --from-env-file=path/to/data.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basename ...
Create a new config map named app-name-config in which the 'properties' key is populated from the '/path/to/configurations/file1.txt' file, and the 'key1' key is populated from the '/path/to/data/file2.txt' file.
Command: ```bash kubectl create configmap app-name-config --from-file=properties=/path/to/configurations/file1.txt --from-file=key1=/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 cre...
update the backend-microservice-deployment by setting the API_KEY environment variable to your-api-key
Command: ```bash kubectl set env deployment/backend-microservice-deployment API_KEY=your-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 more p...
Forward all traffic on port 8080 to port 3000 in the pod named 'api-service-pod', listening on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 8080: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 w...
Create a deployment named 'monitoring' with the image 'nginx' and run the command 'nginx' inside the container
Command: ```bash kubectl create deployment monitoring --image=nginx -- nginx ``` 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: j...
Start forwarding traffic from port 8000 on all addresses to port 8088 in the backend-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8000: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 ...
Embed the certificate authority data for the cluster-gamma cluster entry by using the command "kubectl config set-cluster cluster-gamma --embed-certs --certificate-authority=~/.kube/data-cluster/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster cluster-gamma --embed-certs --certificate-authority=~/.kube/data-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...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ local file to the /etc/kubernetes directory in the remote monitoring-agent-pod-6 pod, specifically in the front-end-container container.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ monitoring-agent-pod-6:/etc/kubernetes -c front-end-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", "def...
Import the REDIS_HOST key from the app-settings config map into the backend-microservice-deployment deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --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 variable d...
Create a new config map named app-secrets using the properties and key1 files as values for the specified keys
Command: ```bash kubectl create configmap app-secrets --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creatin...
Create an ingress called 'api-v2-ingress' with the following rule: direct requests to 'website.com/bar' to the service 'svc1' on port '8000' with the TLS secret 'my-cert'
Command: ```bash kubectl create ingress api-v2-ingress --rule="website.com/bar=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": "", "usage...
Create a deployment named "logging" with the postgres image and expose port 8084
Command: ```bash kubectl create deployment logging --image=postgres --port=8084 ``` 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 an ingress resource called 'public-service-ingress' with a rule that directs requests from "testing.com/bar" to the service 'svc1' at port '9091' using the TLS secret 'my-cert'
Command: ```bash kubectl create ingress public-service-ingress --rule="testing.com/bar=svc1:9091,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": ""...