prompt
stringlengths
13
282
response
stringlengths
128
3.11k
List the deployments in the "rc-1.1.0" version of the "api-v2" API group in YAML output format.
Command: ```bash kubectl get deployments.rc-1.1.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 will o...
Create a new ClusterIP service named api-service-clusterip that maps port 3001 on the cluster to port 8080 on the service.
Command: ```bash kubectl create service clusterip api-service-clusterip --tcp=3001:8080 ``` 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...
Create a new config map named monitoring-config and populate it with files from the specified folder.
Command: ```bash kubectl create configmap monitoring-config --from-file=path/to/options ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the base...
Copy the file `/tmp/foo` from the remote pod `admin-dashboard-pod-16` to the local directory `/tmp/bar_dir`
Command: ```bash kubectl cp kube-proxy/admin-dashboard-pod-16::/tmp/foo /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...
Copy the file /tmp/foo from a remote pod to the local directory /etc/kubernetes.
Command: ```bash kubectl cp kubeapps/image-resizer-pod-20:/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, use t...
Copy the `~/.config/kube` directory from the `cert-manager/payment-gateway-pod-19` pod to the `/tmp/bar_dir` directory on your local machine.
Command: ```bash kubectl cp cert-manager/payment-gateway-pod-19:~/.config/kube /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 omitt...
Create a pod with Elasticsearch image and expose port 8088
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --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] ...
Create a cluster role binding for multiple users and a group using a specific cluster role
Command: ```bash kubectl create clusterrolebinding bar --clusterrole=bar --user=developer3 --user=k8s-admin --group=qa-engineers ``` What it does: Create a cluster role binding for a particular cluster role. Syntax: `kubectl create clusterrolebinding NAME --clusterrole=NAME [--user=username] [--group=groupname] [--se...
Start a new pod named 'hazelcast' using the 'hazelcast/hazelcast' image and expose port 8888
Command: ```bash kubectl run hazelcast --image=hazelcast/hazelcast --port=8888 ``` 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:...
Forward traffic from port 5000 on all addresses to port 3000 in the pod named web-app-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 5000:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will ...
Retrieve the details of the 'web' replication controller, the 'auth-service-rc' service, and the 'payment-gateway-pod' pod
Command: ```bash kubectl get rc/web service/auth-service-rc pods/payment-gateway-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 n...
Add a taint with key 'environment' on nodes having label component=proxy, the node 'edge-node-10' should not schedule new pods unless they tolerate this taint.
Command: ```bash kubectl taint node -l component=proxy environment=edge-node-10:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Remove the label 'bar' from the 'proxy' pod if it exists
Command: ```bash kubectl label pods proxy unhealthy- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If t...
Create a job named "data-migration-job" using the "wordpress" image and execute the "wp" command
Command: ```bash kubectl create job data-migration-job --image=wordpress -- wp ``` 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....
Copy the local file /tmp/foo_dir to the /etc/kubernetes directory in the worker-pod-4 pod, specifically in the backend-container container.
Command: ```bash kubectl cp /tmp/foo_dir worker-pod-4:/etc/kubernetes -c backend-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", "default": "", "usage": "Container name. If omitte...
Listen on local port 6379 and forward it to port 9090 in the 'chat-app-pod' pod
Command: ```bash kubectl port-forward pod/chat-app-pod 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 selected autom...
Forward port 6379 on localhost and IP 10.19.21.23 to port 6379 in the pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-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 cri...
Get output from "mycontainer" in "proxy-server-pod"
Command: ```bash kubectl attach proxy-server-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,...
Import the 'my-example-key' keys from the 'ui-config' config map to the deployment 'order-processing-deployment'
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/ui-config 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 defi...
Forward port 5000 on all addresses to port 9090 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 5000: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 ...
Get the output of the 'composer --version' command running in the 'warp-drive' container of the 'database-pod' pod.
Command: ```bash kubectl exec database-pod -c warp-drive -- composer --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 omit...
Set the resource request and limits for all containers in the Redis deployment.
Command: ```bash kubectl set resources deployment redis --limits=cpu=200m,memory=512Mi --requests=cpu=500m,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 reques...
Execute the 'ash' command in the 'nano-bot' container of the 'email-service-pod' pod and get the output.
Command: ```bash kubectl exec email-service-pod -c nano-bot -- ash ``` 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...
Execute the 'wp' command inside the pod named mypod and retrieve the output
Command: ```bash kubectl exec mypod -- 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 kubectl.kubernetes.io/de...
Add the annotation "deployment-script" with the value "https://example.com/deploy.sh" to the pod identified by type and name in the "setup.json" file.
Command: ```bash kubectl annotate -f setup.json deployment-script='https://example.com/deploy.sh' ``` 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 tha...
Forward port 8000 to port 5432 on the pod "backend-pod" for all addresses
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8000: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 ...
Stream the logs of the "stardust-shuttle" container in the "log-aggregator-pod" pod
Command: ```bash kubectl logs -f -c stardust-shuttle log-aggregator-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...
Add a taint with key 'special' on nodes having label namespace=mynamespace
Command: ```bash kubectl taint node -l namespace=mynamespace special=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": "", "usa...
create a job named batch-processing with the image php and run the command composer --version
Command: ```bash kubectl create job batch-processing --image=php -- composer --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...
Listen on all addresses on port 3000 and forward the traffic to port 8888 in the pod named 'web-app-pod'
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 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 will ...
Add a taint with the key 'hardware' and value 'app-node-6:PreferNoSchedule' on nodes having the label feature=feature-xyz.
Command: ```bash kubectl taint node -l feature=feature-xyz hardware=app-node-6:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
List deployments in JSON output format using the "alpha-2.0" version of the "my-apps" API group.
Command: ```bash kubectl get deployments.alpha-2.0.my-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will...
Open the 'gateway-service' service for editing using the 'gedit' editor
Command: ```bash KUBE_EDITOR="gedit" kubectl edit svc/gateway-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 variable...
Delete resources defined in the kustomization.yaml file in the settings directory.
Command: ```bash kubectl delete -k settings/ ``` 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 resources...
Set the 'team' annotation of the 'vpn' pod to 'frontend-team', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods vpn team='frontend-team' ``` 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 a...
Create an ingress called 'private-ingress' that directs requests to a specific path and service, with a TLS secret.
Command: ```bash kubectl create ingress private-ingress --rule="site.com/module=svc1:8000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Attach to the "rocket-ranger" container in the "cdn-service-pod" pod and get its output.
Command: ```bash kubectl attach cdn-service-pod -c rocket-ranger ``` 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...
Add a taint with the key 'dedicated' and value 'monitoring-node-15:PreferNoSchedule' to all nodes that have the label 'stack=tech-stack'
Command: ```bash kubectl taint node -l stack=tech-stack 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": "",...
Forward traffic from a local random port to port 8888 in the frontend-pod pod.
Command: ```bash kubectl port-forward pod/frontend-pod :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 automatic...
Add a taint with key 'special' on nodes having label environment=production
Command: ```bash kubectl taint node -l environment=production special=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": "", "u...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=secret_key --from=configmap/log-config deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Create a service for the pod named "vpn-service-pod", which serves on port 5001 and is named "frontend"
Command: ```bash kubectl expose pod vpn-service-pod --port=5001 --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 ...
Auto scale the 'database' deployment by creating between 7 and 10 pods.
Command: ```bash kubectl autoscale deployment database --min=7 --max=10 ``` 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...
Add a taint with key 'zone' on nodes having label owner=john-doe, and the value 'edge-node-10:PreferNoSchedule'
Command: ```bash kubectl taint node -l owner=john-doe zone=edge-node-10:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Ou...
Delete the pods and services with the names "security" and "vpn".
Command: ```bash kubectl delete pod,service security vpn ``` 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...
Set the custom TLS server name to use for validation for the 'cluster-beta' cluster entry to 'cluster-alpha'
Command: ```bash kubectl config set-cluster cluster-beta --tls-server-name=cluster-alpha ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificat...
Set the cluster field in a context
Command: ```bash kubectl config set contexts.client-1-context.cluster edge-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 deployment named "db" with the image "jenkins" and expose port 9091.
Command: ```bash kubectl create deployment db --image=jenkins --port=9091 ``` 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...
Set up autoscaling for the 'chat-app' deployment, with a minimum of 6 pods and a maximum of 8 pods.
Command: ```bash kubectl autoscale deployment chat-app --min=6 --max=8 ``` 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...
Start a pod named 'hazelcast' using the 'mongo' container image, and expose port 5432.
Command: ```bash kubectl run hazelcast --image=mongo --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": "--fi...
Update the 'media-stream' pod label to "status=unhealthy" only if the pod's resource version is still 1
Command: ```bash kubectl label pods media-stream 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", ...
Create a pod disruption budget named web-app-pdb that selects all pods with the owner=team-1 label and requires a minimum of four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget web-app-pdb --selector=owner=team-1 --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 [--dr...
Create a priority class with the name "security-priority" that has a value of 800 and a description of "Priority for security-critical workloads"
Command: ```bash kubectl create priorityclass security-priority --value=800 --description="Priority for security-critical workloads" --preemption-policy="Never" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=V...
Create a new ClusterIP service named 'security-service-clusterip', forward traffic from port 8080 to port 9000.
Command: ```bash kubectl create service clusterip security-service-clusterip --tcp=8080:9000 ``` 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...
Embed the certificate authority data for the e2e cluster entry
Command: ```bash kubectl config set-cluster e2e --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-cluster ...
Create a new ExternalName service named 'external-notification-service' with an external name of 'practice-online.site'
Command: ```bash kubectl create service externalname external-notification-service --external-name practice-online.site ``` 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 refe...
Attach to the code explorer container in the analytics pod to access the raw terminal mode
Command: ```bash kubectl attach analytics-pod -c code-explorer -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...
Retrieve information about the replication controller "web", the service "service", the pod "log-aggregator-rc", and the pod "database-pod".
Command: ```bash kubectl get rc/web service/log-aggregator-rc pods/database-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 namesp...
Forward data between ports 9090 and 6379 on your local machine to ports 6000 and 6379 on the analytics-pod pod
Command: ```bash kubectl port-forward pod/analytics-pod 9090 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...
Create a copy of media-stream-pod with all container images changed to confluentinc/cp-kafka
Command: ```bash kubectl debug media-stream-pod --copy-to=debug-image-memcached --set-image=*=confluentinc/cp-kafka ``` 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 ...
Import the MAX_CONNECTIONS key from the global-config ConfigMap into the frontend-deployment deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/global-config 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 definit...
Add a taint with the key 'datacenter' and the value 'db-node-7:PreferNoSchedule' on the nodes that have the label 'owner=john-doe'
Command: ```bash kubectl taint node -l owner=john-doe datacenter=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": ...
Return snapshot logs from container e-commerce-pod-1 of the payment-processor-deployment deployment
Command: ```bash kubectl logs deployment/payment-processor-deployment -c e-commerce-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags...
Listen on port 3000 on your local machine, forwarding traffic to port 5432 in the 'web-app-pod' pod.
Command: ```bash kubectl port-forward pod/web-app-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 will be selected automa...
Embed the certificate authority data for the moon-cluster cluster entry by running the command "kubectl config set-cluster moon-cluster --embed-certs --certificate-authority=~/.kube/edge-cluster/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster moon-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...
Return the snapshot logs from the 'monitoring-pod' container in the 'api-server-deployment-1' deployment
Command: ```bash kubectl logs deployment/api-server-deployment -c monitoring-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag...
Forward local port 8888 to port 3000 in a pod selected by the deployment
Command: ```bash kubectl port-forward deployment/database-deployment 8888 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 ...
Create an ingress called 'api-v2-ingress' with a rule that directs requests from site.com/example to svc1:8083, and use the tls secret "my-cert" for secure communication.
Command: ```bash kubectl create ingress api-v2-ingress --rule="site.com/example=svc1:8083,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Set the custom TLS server name to use for validation for the 'edge-cluster' cluster entry
Command: ```bash kubectl config set-cluster edge-cluster --tls-server-name=cloud-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] [--certificat...
Copy the `~/.config/kube` directory from the remote pod named `rook-ceph/file-server-pod-14` to the local directory `/tmp/bar`.
Command: ```bash kubectl cp rook-ceph/file-server-pod-14:~/.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 th...
Create a debug copy of log-aggregator-pod with a different container image
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-1 --image=debian --set-image=cache=redis:alpine,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resourc...
Start a pod named "hazelcast" using the image "confluentinc/cp-kafka" and expose port 3000 on the container.
Command: ```bash kubectl run hazelcast --image=confluentinc/cp-kafka --port=3000 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flag...
Get the output of running a command inside a pod
Command: ```bash kubectl exec auth-service-pod -- java -jar /usr/share/jenkins/jenkins.war ``` 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 n...
set the environment variables 'smtp_server' from the 'global-config' config map for the 'email-server-deployment' deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/global-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 definit...
Create an ingress called 'api-gateway-ingress' that directs requests to site.com/module to a service called 'svc1' running on port 9092, with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress api-gateway-ingress --rule="site.com/module=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": "", "...
Create a role named "default_role" with the following permissions:
Command: ```bash kubectl create role default_role --verb=exec --resource=pods --resource-name=backup-service --resource-name=content-delivery ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=...
Import the specific key 'API_KEY' from the 'ui-config' config map and set it as an environment variable in the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/ui-config 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 definit...
View the logs of the previous terminated "cyber-sleuth" container in the "media-stream-pod" pod.
Command: ```bash kubectl logs -p -c cyber-sleuth media-stream-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",...
Create a new config map named ui-config using the key=value pairs in the file located at path/to/configurations.
Command: ```bash kubectl create configmap ui-config --from-file=path/to/configurations ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basen...
Start a pod named 'hazelcast' using the 'postgres' image and expose port 9090 inside the container.
Command: ```bash kubectl run hazelcast --image=postgres --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] [args...]` Helpful flags: "flag": "-...
Create a cluster role named "custom_role" with ResourceName specified
Command: ```bash kubectl create clusterrole custom_role --verb=create --resource=pods --resource-name=load-balancer --resource-name=dashboard-ui ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|clie...
Forward local port to pod port
Command: ```bash kubectl port-forward pod/chat-app-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 autom...
create a new NodePort service named web-app-nodeport
Command: ```bash kubectl create service nodeport web-app-nodeport --tcp=5432:9091 ``` 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": "",...
List the replication controller named "web", service named "payment-gateway-rc", and pod named "cdn-service-pod"
Command: ```bash kubectl get rc/web service/payment-gateway-rc pods/cdn-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 na...
Forward local ports to pod ports
Command: ```bash kubectl port-forward pod/mypod 8081 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Set the cluster field of the team-beta-context context to "cloud-cluster"
Command: ```bash kubectl config set contexts.team-beta-context.cluster cloud-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 y...
Forward port 6379 of the pod "api-service-pod" to port 6379 on all addresses
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-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 w...
Run the command 'mysql --version' inside the 'stardust-shuttle' container of the 'backend-pod' pod and display the output.
Command: ```bash kubectl exec backend-pod -c stardust-shuttle -- mysql --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 a replication controller as a service with specific port mappings
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=5000 --target-port=500000 ``` 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...
Create a secret with keys for each file in the specified folder.
Command: ```bash kubectl create secret generic monitoring-credentials-secret --from-file=path/to/configurations ``` 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...
Create an ingress named 'external-ingress' with a rule that directs requests from foo.com/module to svc1:8082, using the TLS secret named "my-cert".
Command: ```bash kubectl create ingress external-ingress --rule="foo.com/module=svc1:8082,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Set the user field to "cluster-admin" on the "on-prem-context" context entry without modifying other values.
Command: ```bash kubectl config set-context on-prem-context --user=cluster-admin ``` What it does: Set a context entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-context [NAME | --current] [--cluster=cluster_nickna...
Scale the deployment named prod-app-rs from 5 replicas to 7 replicas
Command: ```bash kubectl scale --current-replicas=5 --replicas=7 deployment/prod-app-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version...
Copy the ~/.config/kube file from a remote pod named "api-server-pod-3" to the local directory /tmp/bar.
Command: ```bash kubectl cp kubeapps/api-server-pod-3:~/.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 k...
Set the service account of the 'mydeployment' deployment to 'spinnaker'
Command: ```bash kubectl set serviceaccount deployment mydeployment spinnaker ``` 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 se...
Forward port 3000 from localhost and IP address 10.19.21.23 to port 3000 in the 'web-app-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 3000: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 criteri...
Embed the certificate authority data for the e2e cluster entry
Command: ```bash kubectl config set-cluster e2e --embed-certs --certificate-authority=~/.kube/web-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-cluster N...
Retrieve the output from running the 'elasticsearch' command in the 'mycontainer' container from the 'analytics-pod' pod.
Command: ```bash kubectl exec analytics-pod -c mycontainer -- 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 omitted...
Update the image of all containers in the 'namespace-3' daemonset to 'httpd:2.4.48'
Command: ```bash kubectl set image daemonset namespace-3 *=httpd:2.4.48 ``` 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: ...
Create a new secret named database-secret with keys for each file in the path/to/profiles folder
Command: ```bash kubectl create secret generic database-secret --from-file=path/to/profiles ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basename of ...