prompt
stringlengths
13
282
response
stringlengths
128
3.11k
import the DATABASE_URL key from the config map named app-config-dev to the environment variables of the gateway-deployment deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-config-dev 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 definition...
Create a copy of a pod named "database-pod" with a debug container and change the container images for the "logger" and "scheduler" containers.
Command: ```bash kubectl debug database-pod -it --copy-to=debug-image-memcached --image=debian --set-image=logger=logging-app:debug,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects ide...
attach to the gateway-pod container named time-machine and switch to raw terminal mode, allowing you to interact with the bash shell in the container.
Command: ```bash kubectl attach gateway-pod -c time-machine -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 omitte...
Retrieve the previous terminated logs of the "lunar-launcher" container from the "e-commerce-pod" pod
Command: ```bash kubectl logs -p -c lunar-launcher e-commerce-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",...
Mark node "edge-node-10" as schedulable
Command: ```bash kubectl uncordon edge-node-10 ``` What it does: Mark node as schedulable. Syntax: `kubectl uncordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
update the annotation 'git-repo' of the 'frontend' pod with the value 'https://github.com/example/my-app', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods frontend git-repo='https://github.com/example/my-app' ``` 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 lar...
List the replication controller named "web", the service named "chat-app", and the pod named "api-service-pod"
Command: ```bash kubectl get rc/web service/chat-app-rc pods/api-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespace...
Set the new exec auth plugin arguments for the "cluster-admin" entry by using the command "kubectl config set-credentials cluster-admin --exec-arg=arg1 --exec-arg=arg2"
Command: ```bash kubectl config set-credentials cluster-admin --exec-arg=arg1 --exec-arg=arg2 ``` 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 Bearer to...
Forward traffic from port 8080 on all addresses to port 9090 in the pod named log-aggregator-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 8080: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 po...
Update the pods with the label 'role' set to 'frontend' for the pod named 'auth'
Command: ```bash kubectl label pods auth role=frontend ``` 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...
Attach to the astro-container in the analytics-pod and enter the raw terminal mode
Command: ```bash kubectl attach analytics-pod -c astro-container -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Update the 'backend' pod by setting the annotation 'contact-email' to 'support@example.com', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods backend 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 l...
Embed certificate authority data for the prod-cluster cluster entry
Command: ```bash kubectl config set-cluster prod-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 ...
Listen on port 8081 locally, forwarding to port 3000 in the 'api-service-pod' pod
Command: ```bash kubectl port-forward pod/api-service-pod 8081:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Return the snapshot of the previous terminated 'astro-container' container logs from the 'payment-gateway-pod' pod
Command: ```bash kubectl logs -p -c astro-container 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": "--conta...
Forward port 3000 on your local machine to port 8081 on the pod named "chat-app-pod"
Command: ```bash kubectl port-forward 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 criteria, a pod will be selected autom...
Enable the OpenID Connect auth provider for the "service-account" entry with additional arguments client-id=foo and client-secret=bar
Command: ```bash kubectl config set-credentials service-account --auth-provider=oidc --auth-provider-arg=client-id=foo --auth-provider-arg=client-secret=bar ``` 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:...
Create a config map named db-config from specified files
Command: ```bash kubectl create configmap db-config --from-file=conf=/path/to/parameters/file1.txt --from-file=data=/path/to/data/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config m...
Import the environment variables from the 'jwt-secret' secret and apply them to the 'user-management-deployment' deployment.
Command: ```bash kubectl set env --from=secret/jwt-secret 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 definitions in one or more po...
Retrieve the output from running the 'go version' command in the 'nano-bot' container of the 'e-commerce-pod' pod.
Command: ```bash kubectl exec e-commerce-pod -c nano-bot -- go version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use...
Copy the file "/tmp/foo" from the pod "metrics-exporter-pod-10" in the "prometheus" namespace to the local directory "/etc/kubernetes".
Command: ```bash kubectl cp prometheus/metrics-exporter-pod-10:/tmp/foo /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, ...
Execute the 'redis-cli' command in the 'rocket-ranger' container of the 'auth-service-pod' pod.
Command: ```bash kubectl exec auth-service-pod -c rocket-ranger -- redis-cli ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitte...
Forward port 9090 on localhost and IP address 10.19.21.23 to port 8888 in the pod named "mypod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 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 p...
Create a copy of the 'backend-pod' pod, changing the command of the 'time-machine' container to 'sh'.
Command: ```bash kubectl debug backend-pod -it --copy-to=dgb-img --container=time-machine -- 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 by default if n...
Apply a taint to the 'backup-node-14' node with the key 'workload', value 'high-priority', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes backup-node-14 workload=high-priority: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...
Import environment variables from a config map with a specific prefix
Command: ```bash kubectl set env --from=configmap/monitoring-config --prefix=MYSQL_ deployment/cache-cluster-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...
Retrieve the output of the 'geth version' command executed inside the nebula-navigator container in the media-stream-pod.
Command: ```bash kubectl exec media-stream-pod -c nebula-navigator -- geth 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 ...
Copy the contents of the local file /var/run/secrets/kubernetes.io/serviceaccount/ to the remote pod kube-dns/cache-pod-5 in the namespace, and save it as /tmp/bar.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ kube-dns/cache-pod-5::/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 ...
Attach to the time-machine container in the frontend-pod and get the output
Command: ```bash kubectl attach frontend-pod -c time-machine ``` 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, us...
Create a new ExternalName service named 'external-messaging-service' with the external name 'placeholder-app.app'
Command: ```bash kubectl create service externalname external-messaging-service --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 referenc...
Expose a replication controller as a service on a specific port
Command: ```bash kubectl expose -f python-controller.yaml --port=8082 --target-port=800000 ``` 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 /var/run/secrets/kubernetes.io/serviceaccount/ file from your local machine to the /tmp/bar directory in the backend-pod-13 pod in the istio-system namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ istio-system/backend-pod-13::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Con...
Copy the file "~/.config/kube" from the local machine to the path "/tmp/bar" on the remote pod "monitoring-agent-pod-6" in the "kubeapps" namespace.
Command: ```bash kubectl cp ~/.config/kube kubeapps/monitoring-agent-pod-6::/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...
Label the pods with 'security' as the key and 'unhealthy' as the value, but only if the resource version is 1
Command: ```bash kubectl label pods security status=unhealthy --resource-version=1 ``` 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", "def...
Add a taint with the key 'zone' and value 'kube-master-9:PreferNoSchedule' on nodes having the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha zone=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": "", "usa...
Create an ingress resource called 'api-ingress' that directs requests from website.com/input to the service 'svc1' on port 9092
Command: ```bash kubectl create ingress api-ingress --rule="website.com/input=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"...
List deployments in YAML output format from the "feature-branch-2.3.0" version of the "legacy-apps" API group.
Command: ```bash kubectl get deployments.feature-branch-2.3.0.legacy-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 name...
Copy the file "/tmp/foo" from the "argocd/database-pod-2" pod to the "/tmp/bar" directory on your local machine.
Command: ```bash kubectl cp argocd/database-pod-2::/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.kub...
Set the cluster field in the 'testing-context' context to 'cluster-beta'
Command: ```bash kubectl config set contexts.testing-context.cluster cluster-beta ``` 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 ...
Set the environment variables in the local shell that start with "RAILS_" to the deployment named "gateway-deployment" on the server
Command: ```bash env | grep RAILS_ | kubectl set env -e - deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templa...
Add a taint with key 'zone' on nodes having label instance=app-instance-1
Command: ```bash kubectl taint node -l instance=app-instance-1 zone=db-node-7:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Copy the local file /tmp/foo to the remote pod named rook-ceph/cache-pod-5 in the /tmp/bar_dir directory.
Command: ```bash kubectl cp /tmp/foo rook-ceph/cache-pod-5:/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 kubectl....
Import the 'SMTP_SERVER' key from the 'app-settings' config map into the 'mydeployment' deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-settings 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 ...
Retrieve the output of the 'go version' command from the 'warp-drive' container within the 'payment-gateway-pod' pod.
Command: ```bash kubectl exec payment-gateway-pod -c warp-drive -- go version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitt...
List the replication controller named 'web', the service named 'e-commerce-rc', and the pod named 'api-service-pod'.
Command: ```bash kubectl get rc/web service/e-commerce-rc pods/api-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespa...
Create or update the exec auth plugin environment variables for the "saas-admin" entry with the key-value pairs key1=val1 and key2=val2
Command: ```bash kubectl config set-credentials saas-admin --exec-env=key1=val1 --exec-env=key2=val2 ``` 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 Be...
Create a deployment named jenkins using the centos image and expose port 8010
Command: ```bash kubectl create deployment jenkins --image=centos --port=8010 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: ...
Copy the local file, /tmp/foo, to the remote pod with the name payment-gateway-pod-19 in the /tmp/bar_dir directory
Command: ```bash kubectl cp /tmp/foo payment-gateway-pod-19:/tmp/bar_dir -c load-balancer ``` 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...
Set the last-applied-configuration of a resource based on the contents of a file
Command: ```bash kubectl apply set-last-applied -f settings.yaml ``` 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...
Create a new ClusterIP service named my-cs with headless mode
Command: ```bash kubectl create service clusterip my-cs --clusterip="None" ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", ...
Forward local port 5432 to port 3000 on the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 5432:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Create a service for the node deployment, serving on port 80 and connecting to the containers on port 8000
Command: ```bash kubectl expose deployment node --port=80 --target-port=801000 ``` 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 p...
Create a service to expose the specified replication controller, with the service serving on port 80 and connecting to the containers on port 8000.
Command: ```bash kubectl expose -f alpine-controller.yaml --port=80 --target-port=909200 ``` 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 s...
Retrieve the phase value of the 'proxy-service-pod' pod.
Command: ```bash kubectl get -o template pod/proxy-service-pod --template={{.status.phase}} ``` 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 ty...
import the REDIS_HOST key from the config map named "namespace-config" into the "scheduler-app-deployment" deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/namespace-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 defi...
Execute the 'mongo' command inside the 'api-service-pod' pod and retrieve the output from the first container.
Command: ```bash kubectl exec api-service-pod -- mongo ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kub...
Update the annotation 'compliance-level' of pod 'media-stream' to 'PCI-DSS'
Command: ```bash kubectl annotate pods media-stream 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 ...
Delete the pods and services with the names "payment" and "auth"
Command: ```bash kubectl delete pod,service payment auth ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. So...
forward local traffic on port 8000 to the pod 'e-commerce-pod' on port 8888
Command: ```bash kubectl port-forward pod/e-commerce-pod 8000: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 aut...
Create a copy of mypod and add a debug container, changing container images for cache and logger
Command: ```bash kubectl debug mypod -it --copy-to=debug-image-1 --image=debian --set-image=cache=redis:alpine,logger=logging-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...
Delete the app-operator user from the kubectl configuration
Command: ```bash kubectl config delete-user app-operator ``` What it does: Delete the specified user from the kubeconfig. Syntax: `kubectl config delete-user NAME`
Import specific keys from a config map into a deployment.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-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 defi...
Get the list of deployments in the "stable-2.0.0" version of the "custom-deployments" API group in JSON format.
Command: ```bash kubectl get deployments.stable-2.0.0.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 names...
Create a service for the replication controller defined in "ruby-controller.yaml" with the following specifications:
Command: ```bash kubectl expose -f ruby-controller.yaml --port=8089 --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 s...
describe the pod identified by type and name in a config file
Command: ```bash kubectl describe -f config.json ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type, provide a na...
Import the EXTERNAL_API_URL key from the 'namespace-config' config map and set it as an environment variable for the 'mydeployment' deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/namespace-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 definition...
Attach to the container "mycontainer" running in the pod "proxy-service-pod" and get the output from it.
Command: ```bash kubectl attach proxy-service-pod -c mycontainer ``` 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...
Set the custom TLS server name to "cluster-beta" for the "cloud-cluster" cluster entry.
Command: ```bash kubectl config set-cluster cloud-cluster --tls-server-name=cluster-beta ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificat...
Apply a taint to the 'worker-node-3' node with the key 'disktype', value 'ssd', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes worker-node-3 disktype=ssd: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. On...
Set custom TLS server name for a cluster
Command: ```bash kubectl config set-cluster testing-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] [--certif...
Create a deployment named registry using the mysql image.
Command: ```bash kubectl create deployment registry --image=mysql ``` 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|na...
Retrieve the logs from container "log-aggregator-deployment-1" of the "api-service-pod" deployment
Command: ```bash kubectl logs deployment/log-aggregator-deployment -c api-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: ...
Update the image of all containers in the 'test' daemonset to 'node:14.17.3'
Command: ```bash kubectl set image daemonset test *=node:14.17.3 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `kubect...
Attach to the container named "warp-drive" in the pod "web-app-pod" and view its output
Command: ```bash kubectl attach web-app-pod -c warp-drive ``` 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, use t...
Embed the certificate authority data for the 'edge-cluster' cluster entry by running the command:
Command: ```bash kubectl config set-cluster edge-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...
Add a taint with key 'zone' and value 'k8s-node-1:PreferNoSchedule' on nodes having the label 'release=beta'.
Command: ```bash kubectl taint node -l release=beta zone=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": "", "usage": "Output...
Create a new NodePort service named gateway-nodeport with port mapping 8083:8083
Command: ```bash kubectl create service nodeport gateway-nodeport --tcp=8083:8083 ``` 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": "",...
Create a job for a deployment rollout with a specific image and command
Command: ```bash kubectl create job deployment-rollout-job --image=jenkins -- jenkins --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"...
Forward local port 3000 to port 9090 in the pod security-service-pod.
Command: ```bash kubectl port-forward pod/security-service-pod 3000: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 select...
Create a copy of a pod named cdn-service-pod, changing the container image of all containers to postgres
Command: ```bash kubectl debug cdn-service-pod --copy-to=my-debugger --set-image=*=postgres ``` 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 re...
set the cpu and memory limits for the postgres container in the deployment to specific values
Command: ```bash kubectl set resources deployment postgres -c=nginx --limits=cpu=50m,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...
Set the service account of the deployment gateway-deployment to my-service-account
Command: ```bash kubectl set serviceaccount deployment gateway-deployment my-service-account ``` 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: ...
Execute the 'bash' command inside the email-service-pod pod.
Command: ```bash kubectl exec email-service-pod -- bash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.ku...
Import the specific keys from the 'config_file_path' in the 'app-secrets' config map into the 'mydeployment' deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-secrets 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 ...
Create a new ExternalName service named 'external-dns-service' with the external name 'bar.com'
Command: ```bash kubectl create service externalname external-dns-service --external-name bar.com ``` 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 ex...
Forward local port 8088 to port 5000 in the selected pod of deployment "notification-handler-deployment"
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 8088 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 ...
List deployments in YAML format with specific API version
Command: ```bash kubectl get deployments.legacy-1.0.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 namespaced you wi...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-config deployment/database-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...
Forward local port 6379 to port 8888 in the pod named frontend-pod
Command: ```bash kubectl port-forward pod/frontend-pod 6379: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...
Import the specific keys 'REDIS_HOST' from the config map 'api-config' into the deployment 'cache-cluster-deployment'
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/api-config deployment/cache-cluster-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...
Create a new ClusterIP service named payment-service-clusterip, listening on port 5001 and forwarding traffic to port 5000.
Command: ```bash kubectl create service clusterip payment-service-clusterip --tcp=5001:5000 ``` 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"...
Set the cluster field in a specific context to a specified cluster
Command: ```bash kubectl config set contexts.client-2-context.cluster data-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you...
Create a copy of the 'gateway-pod' pod with the command 'sh' in the 'astro-container', and name it 'my-debugger'.
Command: ```bash kubectl debug gateway-pod -it --copy-to=my-debugger --container=astro-container -- 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 by defau...
Expose the centos deployment as a service on port 9092, connecting to the containers on port 800000
Command: ```bash kubectl expose deployment centos --port=9092 --target-port=800000 ``` 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 specifi...
Update the 'frontend' pod with the annotation 'backup-strategy' and the value 'daily backups'.
Command: ```bash kubectl annotate pods frontend 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 inclu...
Listen on port 8000 locally, forwarding to port 3000 in the log-aggregator-pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8000:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Retrieve the output from running the command 'pg_dump --version' in the container rocket-ranger of the pod auth-service-pod.
Command: ```bash kubectl exec auth-service-pod -c rocket-ranger -- pg_dump --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. I...
Start a pod named 'hazelcast' using the 'docker.elastic.co/elasticsearch/elasticsearch' image, and expose port 9090.
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --port=9090 ``` 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] ...
Forward local port 6379 to port 9090 in a pod selected by the deployment
Command: ```bash kubectl port-forward deployment/mydeployment 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 selecte...
Forward the local port 5432 to port 8081 in the pod named 'cdn-service-pod'
Command: ```bash kubectl port-forward pod/cdn-service-pod 5432: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...