prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Retrieve the previous terminated logs of the 'cosmic-container' container from the 'monitoring-pod' pod.
Command: ```bash kubectl logs -p -c cosmic-container monitoring-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container...
Create a service for the replicated hazelcast, which will serve on port 8082 and connect to the containers on port 808400
Command: ```bash kubectl expose rc hazelcast --port=8082 --target-port=808400 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Copy the file "/tmp/foo" to the remote pod "worker-pod-4" in the "argocd" namespace and save it as "/tmp/bar".
Command: ```bash kubectl cp :/tmp/foo argocd/worker-pod-4::/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.kube...
Import the 'database_url' key from the 'ui-config' config map and set it as an environment variable for the 'web-app-deployment' deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/ui-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in ...
Update the pod 'media-stream' and set the annotation 'description' with the value 'Web server for marketing site'
Command: ```bash kubectl annotate pods media-stream description='Web server for marketing site' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than ...
Forward traffic from your local machine's port 8081 to port 8081 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 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 a...
Drain a node and evict all the pods gracefully with a specific grace period
Command: ```bash kubectl drain foo --grace-period=1200 ``` What it does: Drain node in preparation for maintenance. The given node will be marked unschedulable to prevent new pods from arriving. 'drain' evicts the pods if the API server supports https://kubernetes.io/docs/concepts/workloads/pods/disruptions/ . Otherwi...
Forward local port 8000 to port 9090 in the pod named "analytics-pod" for accessing the analytics service locally.
Command: ```bash kubectl port-forward pod/analytics-pod 8000: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 auto...
Forward port 5432 on localhost and IP 10.19.21.23 to port 5000 in the pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 5432: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 criter...
Forward traffic from port 8088 on all addresses to port 3000 in the pod named proxy-server-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 8088: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 ...
Retrieve the logs from all containers within pods that have the label 'namespace=mynamespace'
Command: ```bash kubectl logs -l namespace=mynamespace --all-containers=true ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--...
create a role named "bar" with the ability to list pods and specific access to the app-analytics and prod-api-gateway resources
Command: ```bash kubectl create role bar --verb=list --resource=pods --resource-name=app-analytics --resource-name=prod-api-gateway ``` 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=server|cli...
Retrieve the logs for the previous terminated 'code-explorer' container from the 'backend-pod' pod.
Command: ```bash kubectl logs -p -c code-explorer backend-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", "sh...
Import the SMTP_SERVER key from the log-config config map and set it as an environment variable in the authentication-service-deployment deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/log-config deployment/authentication-service-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 ...
Forward local port 6379 to port 8888 of a pod selected by the deployment called email-server-deployment
Command: ```bash kubectl port-forward deployment/email-server-deployment 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...
Delete both the pods and services with the names "chat-app" and "proxy"
Command: ```bash kubectl delete pod,service chat-app proxy ``` 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. ...
Retrieve a list of deployments in the "v1.1.1" version of the "beta-apps" API group, and display the output in JSON format.
Command: ```bash kubectl get deployments.v1.1.1.beta-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 ...
Forward port 8888 from the pod "backend-pod" to port 8888 on the local machine, listening on both localhost and IP 10.19.21.23.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 8888:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteri...
Create a new pod called 'dgb-img' that is a copy of 'auth-service-pod', but with all container images set to 'php'
Command: ```bash kubectl debug auth-service-pod --copy-to=dgb-img --set-image=*=php ``` 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 resource i...
Create an ingress called 'api-gateway-ingress' that routes requests from foo.com/bar to svc1:8888 and uses the tls secret "my-cert"
Command: ```bash kubectl create ingress api-gateway-ingress --rule="foo.com/bar=svc1:8888,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Update the label of the pod 'cdn' to 'role=backend'.
Command: ```bash kubectl label pods cdn role=backend ``` 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...
Retrieve the snapshot logs from the container "security-service-pod-1" of the deployment "mydeployment".
Command: ```bash kubectl logs deployment/mydeployment -c security-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": ...
Attach to the nebula-navigator container in the backend-pod pod and switch to raw terminal mode, allowing stdin to be sent to 'bash' and stdout/stderr to be sent back to the client.
Command: ```bash kubectl attach backend-pod -c nebula-navigator -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 om...
Create a new ExternalName service named external-dns-service with an external name of documentation-tech.tech
Command: ```bash kubectl create service externalname external-dns-service --external-name documentation-tech.tech ``` 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 ...
Forward local port 8888 to the pod port 8888 of the e-commerce-pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 8888:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Set the context to use the 'dev-cluster' cluster.
Command: ```bash kubectl config use-context dev-cluster ``` What it does: Set the current-context in a kubeconfig file. Syntax: `kubectl config use-context CONTEXT_NAME`
Create an ingress resource named 'public-service-ingress' with a rule that directs requests from site.com/module to the service named 'svc1' with port '8083'
Command: ```bash kubectl create ingress public-service-ingress --rule="site.com/module=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": ""...
Copy the directory "/tmp/foo_dir" from a remote pod named "database-pod-2" to the local directory "/tmp/bar".
Command: ```bash kubectl cp ingress-nginx/database-pod-2:/tmp/foo_dir /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the k...
Create a new secret named 'ssl-key-secret' with keys for each file in the 'path/to/configs' folder.
Command: ```bash kubectl create secret generic ssl-key-secret --from-file=path/to/configs ``` 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 th...
Import specific keys from a config map to an environment variable in a deployment.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/api-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 defin...
View the details of daemonset revision 7 for the my-deployment
Command: ```bash kubectl rollout history daemonset/my-deployment --revision=7 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or ...
Create a pod disruption budget named worker-pdb that selects pods with the owner=team-1 label and requires a minimum of 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget worker-pdb --selector=owner=team-1 --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 [--dry...
Forward local traffic from port 8081 to the pod 'web-app-pod' on port 9090
Command: ```bash kubectl port-forward pod/web-app-pod 8081 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 automa...
Create a cluster role binding with the name 'foo' and associate it with the cluster role 'foo'
Command: ```bash kubectl create clusterrolebinding foo --clusterrole=foo --user=admin --user=devops-user --group=operations-team ``` 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...
Remove the taint with key 'environment' and effect 'NoSchedule' from the node 'app-node-6'
Command: ```bash kubectl taint nodes app-node-6 environment: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 o...
Create an ingress named 'website-ingress' that routes requests from testing.com/module to the service svc1 on port 3306, with a TLS certificate named "my-cert".
Command: ```bash kubectl create ingress website-ingress --rule="testing.com/module=svc1:3306,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Set the CPU and memory limits to 200m and 512Mi respectively, and the CPU and memory requests to 5 and 256Mi respectively, for all containers in the alpine deployment.
Command: ```bash kubectl set resources deployment alpine --limits=cpu=200m,memory=512Mi --requests=cpu=5,memory=256Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requeste...
Forward port 5000 locally to port 8080 in the pod "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 5000: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 auto...
View the details of a specific context in your kubeconfig file.
Command: ```bash kubectl config get-contexts user-b-context ``` What it does: Display one or many contexts from the kubeconfig file. Syntax: `kubectl config get-contexts [(-o|--output=)name)]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: name "
Add a taint with key 'workload' on nodes having label stack=tech-stack
Command: ```bash kubectl taint node -l stack=tech-stack workload=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": "", "usag...
Edit the last-applied-configuration annotations of a deployment named "ruby" in YAML format.
Command: ```bash kubectl apply edit-last-applied deployment/ruby ``` What it does: Edit the latest last-applied-configuration annotations of resources from the default editor. The edit-last-applied command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor...
Create a service for the replication controller specified in "php-controller.yaml"
Command: ```bash kubectl expose -f php-controller.yaml --port=9090 --target-port=300000 ``` 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...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-name-config deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Delete the pods and services named "vpn" and "database" using the command `kubectl delete pod,service vpn database`
Command: ```bash kubectl delete pod,service vpn database ``` 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...
import specific keys from a config map into the environment variables of a deployment
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/env-vars deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in on...
Forward port 8000 on all addresses to port 8081 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-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 ...
Autoscale the replication controller "monitoring" with the number of pods between 1 and 3, targeting CPU utilization at 90%.
Command: ```bash kubectl autoscale rc monitoring --max=3 --cpu-percent=90 ``` 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 u...
Remove all the taints with key 'app' from node 'storage-node-13'
Command: ```bash kubectl taint nodes storage-node-13 app- ``` 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|yaml|n...
Add a taint with key 'environment' on nodes having label 'role=database' and the node name is 'edge-node-10', and set the effect to 'PreferNoSchedule'
Command: ```bash kubectl taint node -l role=database 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": "", "usage...
Create an ingress called 'public-api-ingress' with a rule that directs requests from 'testing.com/input' to 'svc1:27017'
Command: ```bash kubectl create ingress public-api-ingress --rule="testing.com/input=svc1:27017,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": "",...
Scale the deployment named mysql to have a size of 7, if its current size is 5
Command: ```bash kubectl scale --current-replicas=5 --replicas=7 deployment/mysql ``` 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 is sp...
create a cron job named 'system-health-check' using the alpine image, running the command 'ash' every minute
Command: ```bash kubectl create cronjob system-health-check --image=alpine --schedule="*/1 * * * *" -- ash ``` 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": "--output", "short": "-o",...
Forward port 6379 on localhost and IP 10.19.21.23 to port 8000 in the log-aggregator-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 6379: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 ...
Execute the 'python --version' command in the 'time-machine' container of the 'frontend-pod' pod.
Command: ```bash kubectl exec frontend-pod -c time-machine -- 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...
List the environment variables defined on the 'search-engine-deployment' deployment
Command: ```bash kubectl set env deployment/search-engine-deployment --list ``` 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 (within ...
Create a copy of the 'email-service-pod' pod with a debug container and change the container images to 'debian' for the debug container, 'nginx:1.21' for the proxy container, and 'my-scheduler:1.0' for the scheduler container
Command: ```bash kubectl debug email-service-pod -it --copy-to=debug-image-memcached --image=debian --set-image=proxy=nginx:1.21,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 identi...
Update the 'security' pod with the annotation 'backup-strategy' and set its value as 'daily-backups', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods security 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 labe...
Attach to the 'cosmic-container' container in the 'log-aggregator-pod' pod, switch to raw terminal mode, and send stdin to 'bash'
Command: ```bash kubectl attach log-aggregator-pod -c cosmic-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...
Import environment variables from a secret
Command: ```bash kubectl set env --from=secret/cert-manager-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 o...
Import only the 'debug_mode' key from the 'kube-system-config' config map into the 'cache-cluster-deployment' deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/kube-system-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 de...
Create a deployment named logging with the amazonlinux image and 5 replicas
Command: ```bash kubectl create deployment logging --image=amazonlinux --replicas=5 ``` 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. On...
Copy the local file '/tmp/foo' to the remote pod 'security-scanner-pod-18' in the namespace 'kubeapps' at the location '/etc/kubernetes'
Command: ```bash kubectl cp :/tmp/foo kubeapps/security-scanner-pod-18:/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, u...
Create a cluster role binding named 'default_role' that grants the 'default_role' cluster role to 'developer3', 'k8s-admin', and the 'qa-engineers' group.
Command: ```bash kubectl create clusterrolebinding default_role --clusterrole=default_role --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] [--grou...
Update the 'backend' pod by adding the annotation 'alert-email' with the value 'alerts@example.com', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods backend alert-email='alerts@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 labe...
Update the pod's contacts email in the "config.json" file
Command: ```bash kubectl annotate -f config.json 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 labels and in...
Output the modified deployment in YAML format without making any changes to the deployment on the server.
Command: ```bash kubectl set env deployment/monitoring-stack-deployment MONGO_URI=mongodb://localhost:27017/mydb -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 defi...
Create a cluster role named "admin_role" with the following permissions: delete access to configmaps, delete access to the resource named "message-queue", and delete access to the resource named "billing-service".
Command: ```bash kubectl create clusterrole admin_role --verb=delete --resource=configmaps --resource-name=message-queue --resource-name=billing-service ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=ser...
Create a deployment named db that runs the jenkins image and expose port 8000.
Command: ```bash kubectl create deployment db --image=jenkins --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": "", "usage": "Output format. One of: json...
Create a role named "foo" with specified ResourceNames
Command: ```bash kubectl create role foo --verb=connect --resource=pods --resource-name=file-storage --resource-name=log-aggregator ``` 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=server|cli...
Create a copy of a pod, adding a debug container and changing container images
Command: ```bash kubectl debug mypod -it --copy-to=my-debugger --image=debian --set-image=database=mysql:5.7,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 identified by resource and...
Create a job with a specific image and command
Command: ```bash kubectl create job monitoring-job --image=postgres -- pg_dump --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...
List the replication controller named 'web', the service named 'cdn-service-rc', and the pods named 'media-stream-pod'
Command: ```bash kubectl get rc/web service/cdn-service-rc pods/media-stream-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 names...
Create a cluster role binding for multiple users and a group using the cluster-admin role
Command: ```bash kubectl create clusterrolebinding cluster-admin --clusterrole=cluster-admin --user=jane.doe --user=bob.smith --group=developers ``` What it does: Create a cluster role binding for a particular cluster role. Syntax: `kubectl create clusterrolebinding NAME --clusterrole=NAME [--user=username] [--group=...
Check if you have permission to list the job named "content-import-job" in the "development" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/content-import-job -n development ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial...
Set the cpu limit of the mysql container in the deployment named "mysql" to "1" and the memory limit to "2Gi"
Command: ```bash kubectl set resources deployment mysql -c=nginx --limits=cpu=1,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 ...
Scale the resource specified in "docker-registry.yaml" to 3 replicas.
Command: ```bash kubectl scale --replicas=3 -f docker-registry.yaml ``` 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 is specified, it is...
List all deployments in the "hotfix-1.1.2" version of the "custom-deployments" API group in YAML output format
Command: ```bash kubectl get deployments.hotfix-1.1.2.custom-deployments -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 names...
Execute the 'geth' command in the 'astro-container' of the 'cdn-service-pod' pod and get the output.
Command: ```bash kubectl exec cdn-service-pod -c astro-container -- geth ``` 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, u...
Create a new pod named 'hazelcast' using the 'confluentinc/cp-kafka' image and expose port 8088 for communication.
Command: ```bash kubectl run hazelcast --image=confluentinc/cp-kafka --port=8088 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flag...
Forward local port 8888 to port 6379 on the pod/proxy-server-pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 8888 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 a...
Create an ingress resource called 'api-gateway-ingress' with a rule that directs requests from site.com/input to svc1:8000
Command: ```bash kubectl create ingress api-gateway-ingress --rule="site.com/input=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": "", "u...
Import specific keys from a config map and set them as environment variables for a deployment
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-config deployment/load-balancer-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 job named 'cleanup' using the php image
Command: ```bash kubectl create job cleanup --image=php -- ``` 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. One of: json|yaml|n...
Create a new config map, "namespace-config", using specified files
Command: ```bash kubectl create configmap namespace-config --from-file=properties=/path/to/properties/file1.txt --from-file=key1=/path/to/settings/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 cr...
Create a pod disruption budget named statefulset-pdb that will select all pods with the region=us-east label and require a minimum of one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget statefulset-pdb --selector=region=us-east --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N...
Get the output from running the 'mysql --version' command in the 'nano-bot' container inside the 'web-app-pod' pod.
Command: ```bash kubectl exec web-app-pod -c nano-bot -- 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 omitted, u...
Create a ClusterIP service named ldap-service-clusterip that maps port 3000 of the service to port 6379 of the backend
Command: ```bash kubectl create service clusterip ldap-service-clusterip --tcp=3000:6379 ``` 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", "...
List all deployments in YAML output format for the "v1.0.0" version of the "mobile-apps" API group.
Command: ```bash kubectl get deployments.v1.0.0.mobile-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 wil...
Create an ingress called 'api-ingress' that directs requests to website.com/module to a specific service and port, and use a TLS secret for secure communication.
Command: ```bash kubectl create ingress api-ingress --rule="website.com/module=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": "", "usage...
Create a service for the alpine-controller replication controller with the specified parameters: serving on port 5001 and connecting to containers on port 808800 using the configuration in the alpine-controller.yaml file.
Command: ```bash kubectl expose -f alpine-controller.yaml --port=5001 --target-port=808800 ``` 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 single ingress called 'app-loadbalancer-ingress' that directs requests to site.com/input to svc # svc1:9091 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="site.com/input=svc1:9091,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "...
Retrieve snapshot logs from the container 'api-service-pod-1' in the deployment 'notification-handler-deployment'
Command: ```bash kubectl logs deployment/notification-handler-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 f...
Add the annotation 'backup-strategy' with the value 'daily backups' to the pod 'backend'
Command: ```bash kubectl annotate pods backend 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 includ...
Create a new config map named ui-config and populate it with the contents of the folder at the path/to/data directory.
Command: ```bash kubectl create configmap ui-config --from-file=path/to/data ``` 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 basename of the...
Create a debug copy of the media-stream-pod, adding a debug container and changing container images
Command: ```bash kubectl debug media-stream-pod -it --copy-to=debug-image-memcached --image=debian --set-image=api=api:v2,app=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...
Create a new pod named "hazelcast" using the "alpine" image, and expose port 8088 in the container.
Command: ```bash kubectl run hazelcast --image=alpine --port=8088 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Create an ingress named 'www-ingress' with a rule that directs requests to site.com/module to the service 'svc1' with port 9092
Command: ```bash kubectl create ingress www-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": "", "usage": ...
Attach to the vpn-service-pod and switch to raw terminal mode, sending stdin to 'bash' in the cosmic-container and sending stdout/stderr from 'bash' back to the client.
Command: ```bash kubectl attach vpn-service-pod -c cosmic-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. I...
Add a taint with the key 'disktype' on nodes having the label 'cluster=my-cluster', and the taint node-1 with the effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l cluster=my-cluster disktype=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": "...
Create a new ExternalName service named external-file-storage-service with the external name placeholder-app.app
Command: ```bash kubectl create service externalname external-file-storage-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 refer...