prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Set the 'user' field on the 'gce' context entry to 'cluster-admin' without modifying any other values.
Command: ```bash kubectl config set-context gce --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_nickname] [--user=...
Add a taint with the key 'hardware' and value 'gpu-node-12:PreferNoSchedule' on nodes that have the label 'instance=app-instance-1'
Command: ```bash kubectl taint node -l instance=app-instance-1 hardware=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": "", ...
Set the cluster field in the specified context to a new cluster.
Command: ```bash kubectl config set contexts.service-account-context.cluster my-k8s-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 ...
Set the CPU limits of the elasticsearch container in the deployment to "2" and the memory limits to "256Mi".
Command: ```bash kubectl set resources deployment elasticsearch -c=nginx --limits=cpu=2,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 ...
Return snapshot logs from the database-pod pod, including all containers.
Command: ```bash kubectl logs database-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": "--container", ...
Set up autoscaling for the deployment "gateway" with a minimum of 7 pods and a maximum of 13 pods
Command: ```bash kubectl autoscale deployment gateway --min=7 --max=13 ``` 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...
Add a taint with the key 'hardware' and value 'prod-node-5:PreferNoSchedule' on the nodes that have the label 'tier=frontend'
Command: ```bash kubectl taint node -l tier=frontend hardware=prod-node-5:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Create a service for the 'wordpress' deployment, serving on port 80 and connecting to the containers on port 8000
Command: ```bash kubectl expose deployment wordpress --port=80 --target-port=808200 ``` 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 specif...
Attach to the 'nano-bot' container in the 'media-stream-pod' pod, and switch to raw terminal mode to send stdin to the 'bash' command.
Command: ```bash kubectl attach media-stream-pod -c nano-bot -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 omitt...
Create a copy of the 'proxy-service-pod' pod named 'debug-image-api' with all container images changed to 'ubuntu'
Command: ```bash kubectl debug proxy-service-pod --copy-to=debug-image-api --set-image=*=ubuntu ``` 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 n...
Check if the current user has permission to list the job named "log-rotation-job" in the "production" namespace
Command: ```bash kubectl auth can-i list jobs.batch/log-rotation-job -n production ``` 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 UR...
Create a copy of the proxy-server-pod with a debug container and change the container images.
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=my-debugger --image=debian --set-image=logger=logging-app:debug,web=nginx:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resou...
Create a service for the replicated ubuntu pods, serving on port 8181 and connecting to the containers on port 300100
Command: ```bash kubectl expose rc ubuntu --port=8181 --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 port....
Forward traffic from local port 8888 to port 8888 in the pod "cdn-service-pod", allowing external access on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 8888: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 w...
Run the 'postgres' command on the first pod of the 'api-server-deployment' deployment and get the output.
Command: ```bash kubectl exec deploy/api-server-deployment -- postgres ``` 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 an ingress named 'external-ingress' that routes requests for 'foo.com/bar' to the service 'svc1:9092' using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress external-ingress --rule="foo.com/bar=svc1:9092,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":...
Copy the local file /tmp/foo_dir to the remote pod front-end-pod-12 in the kube-public namespace, at the path /etc/kubernetes.
Command: ```bash kubectl cp /tmp/foo_dir kube-public/front-end-pod-12:/etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Create a service for a replicated alpine container that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose rc alpine --port=9092 --target-port=909000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/db-config 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 defi...
Forward all traffic on port 3000 to port 5432 in the cdn-service-pod, and listen on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 3000: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 w...
Create a copy of the `api-service-pod` as `debug-image-app` with all container images changed to `mongo`
Command: ```bash kubectl debug api-service-pod --copy-to=debug-image-app --set-image=*=mongo ``` 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 r...
Import the "config_file_path" key from the "kube-system-config" ConfigMap into the "scheduler-app-deployment" Deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/kube-system-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 varia...
Create a new ExternalName service named external-security-service pointing to the external name test-site.org.
Command: ```bash kubectl create service externalname external-security-service --external-name test-site.org ``` 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 servi...
Create a new ClusterIP service named api-service-clusterip
Command: ```bash kubectl create service clusterip api-service-clusterip --tcp=3001:8081 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "d...
Update the pod 'security' with the annotation 'description' and the value 'Web server for marketing site', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods security description='Web server for marketing site' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larg...
Add a taint with key 'dedicated' on nodes having label release=beta to mark them for exclusive use
Command: ```bash kubectl taint node -l release=beta dedicated=monitoring-node-15: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": "", "us...
Create a new NodePort service named 'vpn-service-nodeport' that maps port 9092 on all nodes to port 3000 on the pod
Command: ```bash kubectl create service nodeport vpn-service-nodeport --tcp=9092:3000 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default":...
Approve the Certificate Signing Request (CSR) for 'csr-api-server-2' by running the command "kubectl certificate approve csr-api-server-2".
Command: ```bash kubectl certificate approve csr-api-server-2 ``` What it does: Approve a certificate signing request. kubectl certificate approve allows a cluster admin to approve a certificate signing request (CSR). This action tells a certificate signing controller to issue a certificate to the requestor with the a...
Launch a postgres pod named 'nginx' but customize its specifications using a partial set of values parsed from a JSON object.
Command: ```bash kubectl run nginx --image=postgres --overrides='{ "apiVersion": "hotfix-1.1.2", "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] --...
Forward traffic from a local port to a specific port in a pod
Command: ```bash kubectl port-forward pod/cdn-service-pod :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 automa...
Create a single ingress called 'external-ingress' that directs requests to testing.com/example to svc1:5000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress external-ingress --rule="testing.com/example=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": "", ...
Create a service for the centos-controller replication controller, using the specifications specified in the "centos-controller.yaml" file
Command: ```bash kubectl expose -f centos-controller.yaml --port=8081 --target-port=818100 ``` 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...
Import specific keys from a config map to a deployment's environment variables.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/env-vars deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Start a nginx pod and override the spec with a partial set of values parsed from JSON
Command: ```bash kubectl run nginx --image=nginx --overrides='{ "apiVersion": "v2.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND...
Import the SECRET_KEY key from the app-secrets config map and set it as an environment variable in the order-processing-deployment deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-secrets deployment/order-processing-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Add a label 'release' with the value 'v1.0' to the pod 'security'
Command: ```bash kubectl label pods security 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": ...
Add a taint with the key 'app' on nodes that have the label zone=us-east-1
Command: ```bash kubectl taint node -l zone=us-east-1 app=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": "", "usage": "Output fo...
Set the CPU limits of the wordpress container in the deployment named "wordpress" to "100m" and set the memory limits to "2Gi".
Command: ```bash kubectl set resources deployment wordpress -c=nginx --limits=cpu=100m,memory=2Gi ``` 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 ...
List deployments in JSON output format, specifically in the "rc-1.1.0" version of the "sandbox-apps" API group
Command: ```bash kubectl get deployments.rc-1.1.0.sandbox-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 ...
Copy the ~/.config/kube file from the 'database-pod-2' pod in the 'argocd' namespace to the /tmp/bar directory on your local machine.
Command: ```bash kubectl cp argocd/database-pod-2:~/.config/kube /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubect...
Switch to raw terminal mode and attach to the 'mycontainer' container in the 'api-service-pod' pod
Command: ```bash kubectl attach api-service-pod -c mycontainer -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 omi...
Set the resource request and limits for all containers in the 'amazonlinux' deployment
Command: ```bash kubectl set resources deployment amazonlinux --limits=cpu=200m,memory=512Mi --requests=cpu=200m,memory=128Mi ``` 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 ...
Set a custom TLS server name for the "my-k8s-cluster" cluster entry.
Command: ```bash kubectl config set-cluster my-k8s-cluster --tls-server-name=my-k8s-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] [--certifi...
Embed certificate authority data for the dev-cluster cluster entry by using the provided certificate authority file
Command: ```bash kubectl config set-cluster dev-cluster --embed-certs --certificate-authority=~/.kube/on-prem-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 s...
Import environment variables from a secret for a deployment
Command: ```bash kubectl set env --from=secret/monitoring-credentials-secret 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 mo...
Add the label 'component=web' to the pod named 'proxy'
Command: ```bash kubectl label pods proxy 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": "I...
Set up automatic scaling for the "frontend" deployment, with a minimum of 7 pods and a maximum of 12 pods.
Command: ```bash kubectl autoscale deployment frontend --min=7 --max=12 ``` 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...
Forward traffic from port 5000 on localhost and IP 10.19.21.23 to port 8888 in the frontend-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-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 criter...
Create a service for a replication controller using a YAML file, with the specified port and target port.
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=80 --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 th...
Create a role named "default_role" with access to list pods and specific resources like notification-service and dev-database.
Command: ```bash kubectl create role default_role --verb=list --resource=pods --resource-name=notification-service --resource-name=dev-database ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-ru...
Create a new ClusterIP service named cache-service-clusterip that will forward traffic from port 8081 on the cluster to port 3001 on the service.
Command: ```bash kubectl create service clusterip cache-service-clusterip --tcp=8081:3001 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", ...
replace a pod using the JSON provided in the params.json file
Command: ```bash cat params.json | kubectl replace -f - ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by $ kubectl get TYPE NAME -o yaml Syntax: `kubectl replace -f FI...
Get output from running a command in a pod
Command: ```bash kubectl exec database-pod -- redis-server --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 t...
Import specific environment variables from a config map to a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-name-config 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 variabl...
List deployments in YAML output format for a specific version of an API group
Command: ```bash kubectl get deployments.feature-branch-2.3.0.api-v2 -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 namespace...
Expose a deployment as a service, with the specified ports.
Command: ```bash kubectl expose deployment ruby --port=8080 --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...
Execute the 'postgres' command in the cosmic-container from the vpn-service-pod pod and retrieve the output.
Command: ```bash kubectl exec vpn-service-pod -c cosmic-container -- postgres ``` 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...
Start a pod named hazelcast using the postgres image and expose port 5432 in the container
Command: ```bash kubectl run hazelcast --image=postgres --port=5432 ``` 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": "-...
Forward traffic from port 6379 on both localhost and IP address 10.19.21.23 to port 6379 in the chat-app-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 6379: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 criter...
Copy the `.config/kube` file from a remote pod named `backend-pod-13` in the `ingress-nginx` namespace to the local directory `/tmp/bar`.
Command: ```bash kubectl cp ingress-nginx/backend-pod-13:~/.config/kube /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
Forward traffic from port 9090 on all addresses to port 5000 in the pod named "backend-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 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 pod will ...
Forward local port 6379 to port 6379 in the analytics-pod pod
Command: ```bash kubectl port-forward pod/analytics-pod 6379: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 auto...
Forward local port 6379 to port 8081 in the pod named cdn-service-pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 6379:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Get the output from running the 'wp' command in the first container of the first pod of the loadbalancer-service service.
Command: ```bash kubectl exec svc/loadbalancer-service -- wp ``` 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 kubec...
Create a new config map named app-settings using the parameters from the 'parameters.env' file located at 'path/to/parameters.env'
Command: ```bash kubectl create configmap app-settings --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 th...
Update the label of the pod named 'email' with the label 'release' and the value 'v1.0'.
Command: ```bash kubectl label pods email 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": "If...
Forward traffic from port 8088 on all addresses to port 5432 inside the pod named cdn-service-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-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 w...
Add or update the annotation 'app-version' with the value '2.5.1' for the pod 'auth'
Command: ```bash kubectl annotate pods auth app-version=2.5.1 ``` 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...
Return the snapshot of the previous terminated 'ruby' container logs from the 'monitoring-pod' pod
Command: ```bash kubectl logs -p -c ruby monitoring-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": ...
Get the documentation for a specific field of a resource
Command: ```bash kubectl explain resource=configmaps.spec.selector ``` What it does: List the fields for supported resources. This command describes the fields associated with each supported API resource. Fields are identified via a simple JSONPath identifier: <type>.<fieldName>[.<fieldName>] Add the --recursive flag ...
Execute the command "ruby --version" in the pod named "chat-app-pod" with the container named "stardust-shuttle".
Command: ```bash kubectl exec chat-app-pod -c stardust-shuttle -- 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 om...
Expose the replicated ruby containers on port 80 and connect to them on port 8000.
Command: ```bash kubectl expose rc ruby --port=8181 --target-port=808400 ``` 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...
Return the previous terminated logs of the "cosmic-container" container from the "email-service-pod" pod.
Command: ```bash kubectl logs -p -c cosmic-container 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": "--contai...
Check if the current authenticated user has permissions to list the cron-job job in the monitoring namespace
Command: ```bash kubectl auth can-i list jobs.batch/cron-job -n monitoring ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL that s...
Start streaming the logs of the lunar-launcher container in the payment-gateway-pod
Command: ```bash kubectl logs -f -c lunar-launcher payment-gateway-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--contai...
Forward port 6379 in the pod "api-service-pod" to port 5000 on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 6379: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 w...
Create a cluster role binding for multiple users and a group using a specific cluster role
Command: ```bash kubectl create clusterrolebinding view --clusterrole=view --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] [--serv...
Create a new LoadBalancer service named 'proxy-server-lb', with port mapping from 9000 to 8080
Command: ```bash kubectl create service loadbalancer proxy-server-lb --tcp=9000:8080 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "de...
Execute the "elasticsearch" command in the "code-explorer" container of the "chat-app-pod" pod and display the output.
Command: ```bash kubectl exec chat-app-pod -c code-explorer -- elasticsearch ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitte...
Create a new config map named ui-config, using the specified file paths for the properties and key1 keys.
Command: ```bash kubectl create configmap ui-config --from-file=properties=/path/to/options/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 creating a confi...
Delete the pods and services named "proxy" and "api"
Command: ```bash kubectl delete pod,service proxy api ``` 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. Some ...
Import specific keys from a config map for a deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/ui-config 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 in...
Get the output of running the 'elasticsearch --version' command in the 'rocket-ranger' container of the 'analytics-pod' pod.
Command: ```bash kubectl exec analytics-pod -c rocket-ranger -- 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...
List all deployments in the "apps" API group, but only in the "v1.1.0" version, and output the result in YAML format
Command: ```bash kubectl get deployments.v1.1.0.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 will only ...
create an ingress called ingress1 with multiple hosts and set the pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="site.com/path*=svc:8181" \ --rule="bar.com/admin*=svc2:http" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "s...
Expose a replication controller as a service
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=8888 --target-port=808200 ``` 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...
Copy the local file '/tmp/foo_dir' to '/tmp/bar_dir' in the remote pod 'logging/load-balancer-pod-9' inside the namespace 'logging'.
Command: ```bash kubectl cp /tmp/foo_dir logging/load-balancer-pod-9:/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 th...
Create an ingress named "app-proxy-ingress" that routes requests from "site.com/bar" to "svc1:3000" using the TLS secret "my-cert"
Command: ```bash kubectl create ingress app-proxy-ingress --rule="site.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...
Create an ingress with TLS enabled for two different domains and different path types
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="foo.com/=svc:https,tls" \ --rule="site.com/path/subpath*=othersvc:3000" ``` 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": "--ou...
Create a new ExternalName service named 'external-geolocation-service' with the external address 'education-edu.edu'
Command: ```bash kubectl create service externalname external-geolocation-service --external-name education-edu.edu ``` 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 referenc...
Forward traffic from port 5000 on all addresses to port 8888 in the security-service-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 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 ...
annotate the pod with a criticality level of "high" based on the information in "pod.json"
Command: ```bash kubectl annotate -f pod.json criticality=high ``` 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 stri...
Import the 'secret_key' key from the 'api-config' config map to the 'monitoring-stack-deployment' deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/api-config deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Import specific keys from a config map into the environment variables for a deployment named "user-management-deployment"
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-secrets 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 definition...
Listen on ports 3000 and 8888 locally, forwarding data to/from ports 8888 and 6000 in the 'log-aggregator-deployment' pod selected by the deployment.
Command: ```bash kubectl port-forward deployment/log-aggregator-deployment 3000 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 wi...
Forward local port 5432 to port 8000 in the pod 'cdn-service-pod'
Command: ```bash kubectl port-forward pod/cdn-service-pod 5432 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 au...
Create a pod named 'hazelcast' using the 'nginx' image and expose port 8088 inside the container.
Command: ```bash kubectl run hazelcast --image=nginx --port=8088 ``` 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...
Start streaming the logs of the 'time-machine' container in the 'mypod' pod.
Command: ```bash kubectl logs -f -c time-machine mypod ``` 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": "...
Delete the pods and services with the names "proxy" and "foo"
Command: ```bash kubectl delete pod,service proxy foo ``` 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. Some ...
Forward traffic from port 8080 on all addresses to port 5000 in the pod "log-aggregator-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 8080: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 po...