prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Forward local ports 8081 and 6000 to the ports 8081 and 6000 of the selected pod in the given deployment.
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 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, ...
Update the annotation 'owner' of the pod 'frontend' in Kuberentes with the value 'alice-smith', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods frontend owner='alice-smith' ``` 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...
Create a new config map named "app-config" with specified keys and corresponding file paths on disk.
Command: ```bash kubectl create configmap app-config --from-file=conf=/path/to/data/file1.txt --from-file=data=/path/to/profiles/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 ma...
Update the deployment 'load-balancer-deployment' by adding a new environment variable named CACHE_SIZE with the value of 64MB
Command: ```bash kubectl set env deployment/load-balancer-deployment CACHE_SIZE=64MB ``` 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 templates...
List the replication controller named 'web', the service named 'cdn-service-rc', and the pod named 'security-service-pod'
Command: ```bash kubectl get rc/web service/cdn-service-rc pods/security-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 n...
Remove the label 'bar' from the pod 'database'
Command: ```bash kubectl label pods database component- ``` 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...
Create a new NodePort service called web-app-nodeport forwarding traffic from port 9000 to port 9092 on the pods.
Command: ```bash kubectl create service nodeport web-app-nodeport --tcp=9000:9092 ``` 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 deployment named registry that uses the golang image and exposes port 3306.
Command: ```bash kubectl create deployment registry --image=golang --port=3306 ``` 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:...
Run the 'apk add curl' command inside the first pod of the log-aggregator-deployment deployment.
Command: ```bash kubectl exec deploy/log-aggregator-deployment -- apk add curl ``` 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 custom TLS server name to "star-cluster" for the "app-cluster" cluster entry in the kubectl configuration.
Command: ```bash kubectl config set-cluster app-cluster --tls-server-name=star-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-...
Forward local port 3000 to port 8000 in the pod "mypod"
Command: ```bash kubectl port-forward pod/mypod 3000:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Forward local port 5432 to port 8088 in the pod/cdn-service-pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 5432: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 au...
Create a deployment named "web" using the "docker.elastic.co/elasticsearch/elasticsearch" container image and expose port 8000
Command: ```bash kubectl create deployment web --image=docker.elastic.co/elasticsearch/elasticsearch --port=8000 ``` 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": ""...
Retrieve the output of the 'dotnet --list-sdks' command from the 'web-app-pod' pod in the 'warp-drive' container.
Command: ```bash kubectl exec web-app-pod -c warp-drive -- dotnet --list-sdks ``` 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...
Create a service for the replication controller specified in the "ubuntu-controller.yaml" file, which serves on port 5001 and connects to the containers on port 909000.
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=5001 --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...
Execute the 'mysql' command in the 'security-service-pod' pod, using the first container by default
Command: ```bash kubectl exec security-service-pod -- mysql ``` 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 kubect...
Create a pod disruption budget named 'statefulset-pdb' that will select all pods with the 'tier=frontend' label and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget statefulset-pdb --selector=tier=frontend --min-available=9 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N ...
Create a service for the replicated nginx using a replica set, with the service serving on port 3001 and connecting to the containers on port 637900.
Command: ```bash kubectl expose rs nginx --port=3001 --target-port=637900 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. ...
Create a new ExternalName service named external-analytics-service with the external name "governmental-demo.gov"
Command: ```bash kubectl create service externalname external-analytics-service --external-name governmental-demo.gov ``` 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 refere...
Create a new secret named 'api-secret-key' using the environment variables defined in the 'path/to/configs.env' file
Command: ```bash kubectl create secret generic api-secret-key --from-env-file=path/to/configs.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basena...
Set the service account of the deployment "scheduler-app-deployment" to "flux"
Command: ```bash kubectl set serviceaccount deployment scheduler-app-deployment flux ``` 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...
Expose a replication controller named "ubuntu" as a service, listening on port 8084 and forwarding traffic to the pods on port 8000.
Command: ```bash kubectl expose rc ubuntu --port=8084 --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 specified port....
Output the modified deployment in YAML format without making changes to the server.
Command: ```bash kubectl set env deployment/authentication-service-deployment DB_USER=username -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or ...
Set the cpu limit for the 'nginx' container in the 'ubuntu' deployment to "500m" and the memory limit to "64Mi".
Command: ```bash kubectl set resources deployment ubuntu -c=nginx --limits=cpu=500m,memory=64Mi ``` 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 resource request and limits for all containers in the hazelcast deployment to CPU: 100m and Memory: 512Mi for requests, and CPU: 200m and Memory: 512Mi for limits.
Command: ```bash kubectl set resources deployment hazelcast --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=512Mi ``` 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 re...
Roll back the daemonset/nginx to revision 5.
Command: ```bash kubectl rollout undo daemonset/nginx --to-revision=5 ``` What it does: Roll back to a previous rollout. Syntax: `kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the r...
Get the documentation for the `metadata.annotations` field of a `configmaps` resource.
Command: ```bash kubectl explain resource=configmaps.metadata.annotations ``` 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 --recursiv...
Copy the local file '/tmp/foo_dir' to the remote pod 'web-app-pod-1' in the 'istio-system' namespace, renaming it as '/tmp/bar_dir'
Command: ```bash kubectl cp /tmp/foo_dir istio-system/web-app-pod-1:/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...
Create a service for the 'node' deployment, which serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment node --port=8000 --target-port=808300 ``` 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...
Forward local port 3000 to port 8000 in the CDN service pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 3000: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...
Set cpu and memory limits for a container in a deployment
Command: ```bash kubectl set resources deployment postgres -c=nginx --limits=cpu=200m,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up t...
Apply a taint with key 'cpu-type' on nodes that have the label tier=frontend
Command: ```bash kubectl taint node -l tier=frontend cpu-type=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...
Set the context for the app-cluster cluster
Command: ```bash kubectl config use-context app-cluster ``` What it does: Set the current-context in a kubeconfig file. Syntax: `kubectl config use-context CONTEXT_NAME`
Forward local traffic from port 8000 to port 8080 of pod/mypod.
Command: ```bash kubectl port-forward pod/mypod 8000 8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Create a job to build an image using the provided command.
Command: ```bash kubectl create job image-build-job --image=wordpress -- mysql --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outp...
Forward ports between your local machine and a pod
Command: ```bash kubectl port-forward pod/analytics-pod 8000 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 auto...
Copy the local file `/tmp/foo` to the remote pod `kube-proxy/metrics-exporter-pod-10` in the namespace, and save it as `/tmp/bar`.
Command: ```bash kubectl cp :/tmp/foo kube-proxy/metrics-exporter-pod-10::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Delete pods and services with names "auth" and "cdn"
Command: ```bash kubectl delete pod,service auth cdn ``` 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 r...
Execute the 'elasticsearch-plugin --list' command in the vpn-service-pod and display the output.
Command: ```bash kubectl exec vpn-service-pod -- elasticsearch-plugin --list ``` 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...
Expose a service for a replication controller using a YAML file, specifying the ports to use
Command: ```bash kubectl expose -f php-controller.yaml --port=9091 --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 sp...
List multiple resources by their types and names
Command: ```bash kubectl get rc/web service/proxy-server-rc pods/analytics-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...
Execute the command "dotnet --list-sdks" in the first container of the first pod of the "analytics-service" service
Command: ```bash kubectl exec svc/analytics-service -- dotnet --list-sdks ``` 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, ...
Create a new pod named 'hazelcast' with the centos image and expose port 6379.
Command: ```bash kubectl run hazelcast --image=centos --port=6379 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Create an ingress called 'public-service-ingress' with a rule that directs requests for 'testing.com/input' to the service 'svc1' on port 3000
Command: ```bash kubectl create ingress public-service-ingress --rule="testing.com/input=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": ...
Forward port 5000 of the pod "analytics-pod" to port 8888 on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8888:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Copy the file "/var/run/secrets/kubernetes.io/serviceaccount/" from your local machine to the "/tmp/bar" directory in the "task-processor" container of the "web-app-pod-1" pod.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ web-app-pod-1::/tmp/bar -c task-processor ``` 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": ...
Import the 'REDIS_HOST' key from the 'db-config' config map to the 'notification-handler-deployment' deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/db-config deployment/notification-handler-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 a bash command in the first pod of the deployment "load-balancer-deployment" and retrieve the output.
Command: ```bash kubectl exec deploy/load-balancer-deployment -- 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 ...
Return previous terminated logs of the "cosmic-container" container from the "api-service-pod" pod
Command: ```bash kubectl logs -p -c cosmic-container api-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": "--containe...
Create a pod named 'nginx' with the image 'ethereum/client-go' and override its spec with a partial set of values parsed from the provided JSON.
Command: ```bash kubectl run nginx --image=ethereum/client-go --overrides='{ "apiVersion": "v1.1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command...
Create a new secret named 'api-secret-key' with keys for each file in the 'path/to/settings' folder.
Command: ```bash kubectl create secret generic api-secret-key --from-file=path/to/settings ``` 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 t...
Retrieve a list of deployments in YAML output format, specifically in the "v1.0.0" version of the "my-apps" API group.
Command: ```bash kubectl get deployments.v1.0.0.my-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 on...
Create a debug container from an existing pod by copying the pod and changing all container images to nginx.
Command: ```bash kubectl debug api-service-pod --copy-to=debug-image-api --set-image=*=nginx ``` 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...
Create a new config map named app-config-dev by specifying the keys and their corresponding file paths.
Command: ```bash kubectl create configmap app-config-dev --from-file=conf=/path/to/data/file1.txt --from-file=data=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a con...
Forward traffic from port 9090 on all addresses to port 5000 in the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-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 wi...
Update the annotation 'SLA' of pod 'chat-app' with the value '99.9% uptime', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods chat-app SLA='99.9% uptime' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and includ...
Execute the command "python --version" inside the "cyber-sleuth" container of the "database-pod" pod and display the output.
Command: ```bash kubectl exec database-pod -c cyber-sleuth -- python --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...
Create an ingress named 'api-gateway-ingress' that directs requests to 'testing.com/bar' to 'svc1:9000' with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress api-gateway-ingress --rule="testing.com/bar=svc1:9000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Set the service account of the deployment "web-app-deployment" to "argocd"
Command: ```bash kubectl set serviceaccount deployment web-app-deployment argocd ``` 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...
Add a taint with the key 'cpu-type' and value 'worker-node-3:PreferNoSchedule' on nodes having the label stack=tech-stack
Command: ```bash kubectl taint node -l stack=tech-stack cpu-type=worker-node-3: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...
Create a copy of the e-commerce pod, changing all container images to MySQL for debugging purposes.
Command: ```bash kubectl debug e-commerce-pod --copy-to=my-custom-dbg --set-image=*=mysql ``` 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 reso...
Create a port-forwarding tunnel between your local machine's port 8088 and the selected pod's port 6379, for the deployment named api-server-deployment.
Command: ```bash kubectl port-forward deployment/api-server-deployment 8088 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will b...
Set the PHP container CPU limits to "3" and memory to "4Gi" in the nginx container of the php deployment.
Command: ```bash kubectl set resources deployment php -c=nginx --limits=cpu=3,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 its sp...
import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-settings deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in o...
Attach to a specific container in a pod and interact with it as if it were a local terminal
Command: ```bash kubectl attach backend-pod -c lunar-launcher -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 omit...
Set the cluster field in the my-context context to prod-cluster.
Command: ```bash kubectl config set contexts.on-prem-context.cluster prod-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 ...
Partially update the configuration of a specific node by applying a strategic merge patch in JSON format
Command: ```bash kubectl patch node worker-node-3 -p '{"spec":{"rules":[{"http":{"paths":[{"path":"/","backend":{"service": {"name": "new-service"}}}]}}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl...
Set the resource requests and limits for all containers in the "ruby" deployment.
Command: ```bash kubectl set resources deployment ruby --limits=cpu=200m,memory=512Mi --requests=cpu=2,memory=1Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, b...
Auto scale the deployment "web" to have a minimum of 6 pods and a maximum of 9 pods.
Command: ```bash kubectl autoscale deployment web --min=6 --max=9 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the ...
Create a deployment named my-dep using the golang image and expose port 3306.
Command: ```bash kubectl create deployment my-dep --image=golang --port=3306 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: j...
Add a taint to nodes labeled with 'project=project-alpha' to prefer no scheduling on 'k8s-node-1'
Command: ```bash kubectl taint node -l project=project-alpha datacenter=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": "", "...
Set up autoscaling for the deployment named "auth" with a minimum of 5 pods and a maximum of 9 pods.
Command: ```bash kubectl autoscale deployment auth --min=5 --max=9 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Copy the /tmp/foo_dir directory from the 'prometheus/load-balancer-pod-9' pod to the /tmp/bar_dir directory on the local machine.
Command: ```bash kubectl cp prometheus/load-balancer-pod-9:/tmp/foo_dir /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...
Continuously stream the logs of the nano-bot container in the pod named api-service-pod
Command: ```bash kubectl logs -f -c nano-bot api-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": "--container", "sho...
Add a taint with key 'disktype' on nodes having label environment=production, specifically on the node with the label monitoring-node-15, and set the taint to PreferNoSchedule
Command: ```bash kubectl taint node -l environment=production disktype=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"...
Embed the certificate authority data for the testing-cluster cluster entry using the command 'kubectl config set-cluster testing-cluster --embed-certs --certificate-authority=~/.kube/edge-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster testing-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 ...
Expose the deployment "node" as a service on port 8010, which will connect to the containers on port 9090.
Command: ```bash kubectl expose deployment node --port=8010 --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...
Listen on port 8000 locally and forward to the targetPort of the "https" service's port in the pod selected by the "email-service" service.
Command: ```bash kubectl port-forward service/email-service 8000:https ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Create an ingress named 'default-ingress' that routes requests to testing.com/input to svc1:3000 with the tls secret 'my-cert'
Command: ```bash kubectl create ingress default-ingress --rule="testing.com/input=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": "", "us...
Set the service account for the deployment "cache-cluster-deployment" to be "my-service-account"
Command: ```bash kubectl set serviceaccount deployment cache-cluster-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 Sy...
Create an ingress called 'api-v2-ingress' with a rule that directs requests from 'site.com/example' to 'svc1:8443' using the TLS secret 'my-cert'
Command: ```bash kubectl create ingress api-v2-ingress --rule="site.com/example=svc1:8443,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...
Update the environment variable 'QUEUE_NAME' of the deployment 'order-processing-deployment' to 'task-queue'
Command: ```bash kubectl set env deployment/order-processing-deployment QUEUE_NAME=task-queue ``` 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 ...
Proxy the Kubernetes API with a custom prefix
Command: ```bash kubectl proxy --api-prefix=/custom/ ``` What it does: Creates a proxy server or application-level gateway between localhost and the Kubernetes API server. It also allows serving static content over specified HTTP path. All incoming data enters through one port and gets forwarded to the remote Kubernet...
Update the app version annotation for a pod identified in the setup.json file with the value 2.5.1
Command: ```bash kubectl annotate -f setup.json 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 s...
Forward traffic from port 3000 on all addresses to port 9090 in the pod named "mypod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 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 sel...
Add a taint with key 'hardware' and no value to the node 'testing-node-11'
Command: ```bash kubectl taint nodes testing-node-11 hardware:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One ...
Update the pod identified by the type and name specified in the "params.json" file with the annotation "security-scan-status=pass"
Command: ```bash kubectl annotate -f params.json security-scan-status=pass ``` 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 ar...
Create a copy of the "analytics-pod" by adding a debug container and changing the container images
Command: ```bash kubectl debug analytics-pod -it --copy-to=my-debugger --image=debian --set-image=app=app:debug,api=api:v2 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods w...
Retrieve the logs from the container log-aggregator-deployment-1 of a deployment named proxy-server-pod
Command: ```bash kubectl logs deployment/log-aggregator-deployment -c proxy-server-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:...
Create a new ExternalName service named external-identity-provider-service that points to the external website "dummy-website.io".
Command: ```bash kubectl create service externalname external-identity-provider-service --external-name dummy-website.io ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to ref...
Verify if the current user has permission to list the specified job in the given namespace.
Command: ```bash kubectl auth can-i list jobs.batch/batch-processing-job -n kube-node-lease ``` 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 p...
Set the CPU and memory limits for the nginx container in a deployment to 2 and 2Gi respectively.
Command: ```bash kubectl set resources deployment nginx -c=nginx --limits=cpu=2,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 to its ...
Unset the namespace in a GCE context
Command: ```bash kubectl config unset contexts.gce.namespace ``` What it does: Unset 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. Syntax: `kubectl config unset PROPERTY_NAME`
Partially update a node by patching it with new values specified in YAML format.
Command: ```bash kubectl patch node dev-node-4 -p $'data:\n key: new-value' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful flags:...
Add a taint to the 'node-1' node with key 'workload' and no value
Command: ```bash kubectl taint nodes node-1 workload:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|...
Retrieve the output from running the 'elasticsearch' command in the code-explorer container of the 'proxy-server-pod' pod.
Command: ```bash kubectl exec proxy-server-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 om...
Create a new ClusterIP service named 'database-service-clusterip' that maps the local port '9091' to the service port '8181'
Command: ```bash kubectl create service clusterip database-service-clusterip --tcp=9091:8181 ``` 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...
Update the label of pod 'foo' to 'status=unhealthy' only if the pod's resource version is 1.
Command: ```bash kubectl label pods foo 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", "default"...
Create a cron job named "data-sync" that runs the command "docker run -d ubuntu sleep 3600" every minute
Command: ```bash kubectl create cronjob data-sync --image=ubuntu --schedule="*/1 * * * *" -- docker run -d ubuntu sleep 3600 ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--outpu...
Create a new single ingress called 'frontend-ingress' that directs requests to "site.com/module" to the service 'svc1' on port 8082, and use the TLS secret "my-cert".
Command: ```bash kubectl create ingress rontend-ingress --rule="site.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...