prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Delete the pods and services with the names "email" and "security"
Command: ```bash kubectl delete pod,service email security ``` 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. ...
Check if you have permission to list the job named "queue-processing-job" in the "development" namespace
Command: ```bash kubectl auth can-i list jobs.batch/queue-processing-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 parti...
Create a cron job named "email-notifications" that runs the "nginx" image every minute
Command: ```bash kubectl create cronjob email-notifications --image=nginx --schedule="*/1 * * * *" -- nginx ``` 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"...
Embed the certificate authority data for the "cluster-gamma" cluster entry in the kubeconfig file
Command: ```bash kubectl config set-cluster cluster-gamma --embed-certs --certificate-authority=~/.kube/dev-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...
Import environment variables from the 'db-config' config map with the prefix 'MYSQL_' to the 'cache-cluster-deployment' deployment.
Command: ```bash kubectl set env --from=configmap/db-config --prefix=MYSQL_ deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions i...
Import the CONFIG_FILE_PATH key from the env-vars config map and set it as an environment variable in the monitoring-stack-deployment deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/env-vars deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Set the service account of the 'backend-microservice-deployment' deployment to 'kube-dns'
Command: ```bash kubectl set serviceaccount deployment backend-microservice-deployment kube-dns ``` 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 Synta...
Copy the file "foo" located in the "/tmp" directory on your local machine to the "/tmp/bar" directory inside the "database-pod-2" pod in the "cert-manager" namespace.
Command: ```bash kubectl cp :/tmp/foo cert-manager/database-pod-2::/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 kube...
Set environment variables from specific keys in a config map for a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-secrets 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 definitio...
Set new exec auth plugin args for the "robot-user" entry
Command: ```bash kubectl config set-credentials robot-user --exec-arg=arg1 --exec-arg=arg2 ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=keyfile Bearer token...
Create a copy of the 'monitoring-pod' pod by attaching a debug container to it
Command: ```bash kubectl debug monitoring-pod -it --image=busybox --copy-to=debug-image-1 ``` 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...
Start a pod named nginx using the docker.elastic.co/elasticsearch/elasticsearch image
Command: ```bash kubectl run nginx --image=docker.elastic.co/elasticsearch/elasticsearch --overrides='{ "apiVersion": "feature-branch-2.3.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|cli...
Create a cluster role named "reader" with permissions to watch services, and specific resource names "machine-learning" and "file-processing"
Command: ```bash kubectl create clusterrole reader --verb=watch --resource=services --resource-name=machine-learning --resource-name=file-processing ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|...
Add a taint with key 'workload' on nodes having label feature=feature-xyz
Command: ```bash kubectl taint node -l feature=feature-xyz workload=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...
Create a single ingress called 'app-ingress' that directs requests to site.com/input to svc1:6379 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app-ingress --rule="site.com/input=svc1:6379,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": "...
Scale the deployment named mysql to a size of 5 if its current size is 1.
Command: ```bash kubectl scale --current-replicas=1 --replicas=5 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...
Copy a file from a remote pod to a local directory
Command: ```bash kubectl cp default/admin-dashboard-pod-16:~/.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 t...
Forward traffic from port 3000 on your local machine to port 5432 in the 'security-service-pod' pod
Command: ```bash kubectl port-forward pod/security-service-pod 3000:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Forward traffic from port 8088 on all addresses to port 8081 in the cdn-service-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 8088: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 w...
Edit the service named 'proxy-service' using the default editor
Command: ```bash kubectl edit svc/proxy-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 variables, or fall back to 'vi...
Update the pod named 'frontend' and set its label 'unhealthy' to 'true'
Command: ```bash kubectl label pods frontend unhealthy=true ``` 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"...
Execute the 'mongod' command in the 'code-explorer' container of the 'chat-app-pod' pod and get the output.
Command: ```bash kubectl exec chat-app-pod -c code-explorer -- mongod ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Create a pod named hazelcast using the hazelcast/hazelcast image, and expose port 3306
Command: ```bash kubectl run hazelcast --image=hazelcast/hazelcast --port=3306 ``` 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:...
Create a Pod Disruption Budget named payment-gateway-pdb that will select all pods with the env=production label and require a minimum of one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget payment-gateway-pdb --selector=env=production --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-availab...
Delete the pods and services with the names "proxy" and "auth"
Command: ```bash kubectl delete pod,service proxy auth ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. Some...
Copy the ~/.config/kube local file to /tmp/bar_dir directory in the 'database-pod-2' pod in the kube-server namespace.
Command: ```bash kubectl cp ~/.config/kube kube-server/database-pod-2:/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 t...
Import specific keys from a config map into the environment variables of a deployment
Command: ```bash kubectl set env --keys=database_url --from=configmap/global-config deployment/analytics-platform-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 ...
Create a ClusterIP service named ldap-service-clusterip with the mapping from port 8084 on the service to port 9090 on the target pods.
Command: ```bash kubectl create service clusterip ldap-service-clusterip --tcp=8084:9090 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "...
Set the runtime container CPU limits to "500m" and memory to "2Gi" for the deployment named "runtime" with the container named "nginx"
Command: ```bash kubectl set resources deployment runtime -c=nginx --limits=cpu=500m,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...
Delete pods and services with the names "log-aggregator" and "database"
Command: ```bash kubectl delete pod,service log-aggregator 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 s...
Output the modified 'load-balancer-deployment' deployment in YAML format, without actually altering the object on the server
Command: ```bash kubectl set env deployment/load-balancer-deployment API_KEY=your-api-key -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 more ...
Execute the 'dotnet' command inside the container of the pod named 'log-aggregator-pod' and display the output
Command: ```bash kubectl exec log-aggregator-pod -- dotnet ``` 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...
Update the cluster role binding for tiller by specifying the service account.
Command: ```bash kubectl set subject clusterrolebinding admin --serviceaccount=namespace:tiller ``` What it does: Update the user, group, or service account in a role binding or cluster role binding. Syntax: `kubectl set subject (-f FILENAME | TYPE NAME) [--user=username] [--group=groupname] [--serviceaccount=namespa...
Import specific keys from a config map into an environment variable for a deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --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 defini...
Import the 'redis_host' key from the 'app-name-config' config map and set it as an environment variable for the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-name-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 variabl...
Copy the /tmp/foo_dir directory from a remote pod called worker-pod-4 in the kube-dns namespace to the local /tmp/bar directory.
Command: ```bash kubectl cp kube-dns/worker-pod-4:/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 kubectl....
Forward local port 8088 to port 6379 in the security-service-pod pod.
Command: ```bash kubectl port-forward pod/security-service-pod 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 be select...
Set the custom TLS server name to "my-k8s-cluster" for the "star-cluster" cluster entry.
Command: ```bash kubectl config set-cluster star-cluster --tls-server-name=my-k8s-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifica...
Create a new ExternalName service named external-database-service
Command: ```bash kubectl create service externalname external-database-service --external-name example-domain.com ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference ...
Create a new ExternalName service named external-third-party-api-service, with the external name set to "bar.com"
Command: ```bash kubectl create service externalname external-third-party-api-service --external-name bar.com ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference serv...
Forward local port to pod port
Command: ```bash kubectl port-forward pod/api-service-pod 9090:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Edit the last-applied-configuration annotations of the amazonlinux deployment in YAML
Command: ```bash kubectl apply edit-last-applied deployment/amazonlinux ``` 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...
Remove all taints with the key 'special' from the 'dev-node-4' node
Command: ```bash kubectl taint nodes dev-node-4 special- ``` 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|na...
Create a new ClusterIP service named 'log-service-clusterip' that listens on port 9091 and forwards traffic to port 9091.
Command: ```bash kubectl create service clusterip log-service-clusterip --tcp=9091:9091 ``` 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...
Set the CPU and memory limits to 200m CPU and 512Mi memory, and set the CPU request to 1 CPU and memory request to 512Mi for all containers in the 'ubuntu' deployment.
Command: ```bash kubectl set resources deployment ubuntu --limits=cpu=200m,memory=512Mi --requests=cpu=1,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 requeste...
Forward local port 8081 to port 5432 in the pod named 'security-service-pod'
Command: ```bash kubectl port-forward pod/security-service-pod 8081: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 select...
Forward local port 5432 to port 3000 in the pod 'api-service-pod'
Command: ```bash kubectl port-forward pod/api-service-pod 5432:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Add a taint with key 'environment' on nodes having label 'namespace=mynamespace', set the taint to 'PreferNoSchedule' and apply it to the node 'storage-node-13'
Command: ```bash kubectl taint node -l namespace=mynamespace environment=storage-node-13: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":...
Execute the command 'yum install -y aws-cli' in the container 'cyber-sleuth' of the 'database-pod' pod and retrieve the output.
Command: ```bash kubectl exec database-pod -c cyber-sleuth -- yum install -y aws-cli ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. I...
Run the 'geth' command in the 'mycontainer' container of the 'auth-service-pod' pod and display the output
Command: ```bash kubectl exec auth-service-pod -c mycontainer -- 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, use ...
Forward local port 8000 to port 5000 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward pod/chat-app-pod 8000:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Update the image for all deployments and replication controllers to 'centos:8.4.2105'
Command: ```bash kubectl set image deployments,rc centos=centos:8.4.2105 --all ``` 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) S...
Listen on port 8088 locally and forward traffic to port 8081 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward pod/backend-pod 8088: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 automa...
List the resources defined in the directory 'config/' using the 'kustomization.yaml' file.
Command: ```bash kubectl get -k config/ ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only see results in your c...
Edit the `gateway-service` resource using an alternative editor (in this case, Notepad)
Command: ```bash KUBE_EDITOR="notepad" 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 variab...
Set the resource limits of a deployment's hazelcast container to "500m" for CPU and "512Mi" for memory
Command: ```bash kubectl set resources deployment hazelcast -c=nginx --limits=cpu=500m,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 requested, but may burst u...
Listen on port 9090 locally, forwarding to port 9090 in the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 9090: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 au...
Create an ingress resource named 'myapp-ingress' with a rule that directs requests for 'foo.com/bar' to 'svc1:8083' and uses the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress myapp-ingress --rule="foo.com/bar=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": "", "usage": "O...
Import the smtp_server key from the config map env-vars and set it as an environment variable for the cache-cluster-deployment deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/env-vars 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 definitions...
Start port forwarding from local port 8088 to port 5000 in a pod selected by the 'database-deployment' deployment
Command: ```bash kubectl port-forward deployment/database-deployment 8088 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Add a taint on nodes with a specific label
Command: ```bash kubectl taint node -l namespace=mynamespace hardware=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":...
Create a priority class called 'development-priority' with a value of 15 and a description of "Priority for development and staging"
Command: ```bash kubectl create priorityclass development-priority --value=15 --description="Priority for development and staging" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=VALUE --global-default=BOOL [--...
Roll back the daemonset 'test' to revision 5
Command: ```bash kubectl rollout undo daemonset/test --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 re...
Create a single ingress called 'internal-ingress' that directs requests to site.com/module to svc1:3001 with the TLS secret "my-cert"
Command: ```bash kubectl create ingress internal-ingress --rule="site.com/module=svc1:3001,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": "", "usa...
Create a new ExternalName service named 'external-analytics-service' with an external name of 'sample-domain.net'
Command: ```bash kubectl create service externalname external-analytics-service --external-name sample-domain.net ``` 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 ...
Execute the 'psql' command on the first pod of the api-server-deployment and display the output.
Command: ```bash kubectl exec deploy/api-server-deployment -- psql ``` 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...
Create an ingress resource that directs requests to a specific URL path to a service with a TLS certificate
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="website.com/input=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"...
Create a pod disruption budget named "worker-pdb" that will select all pods with the label "component=web" and ensure that at least one of them is always available.
Command: ```bash kubectl create poddisruptionbudget worker-pdb --selector=component=web --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 [--dr...
Create a new LoadBalancer service named 'monitoring-lb' with port mapping from local port 8888 to container port 8443
Command: ```bash kubectl create service loadbalancer monitoring-lb --tcp=8888:8443 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "defa...
Add a taint with the key 'environment' and the value 'db-node-7:PreferNoSchedule' on all nodes that have the label 'myLabel'
Command: ```bash kubectl taint node -l myLabel environment=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": "Outpu...
Update the annotation of the pod 'proxy-server' with the key 'custom-label' and the value 'my-custom-value', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods proxy-server custom-label='my-custom-value' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than l...
Create an ingress named 'service-ingress' with a rule that directs requests from site.com/example to svc1:8084
Command: ```bash kubectl create ingress service-ingress --rule="site.com/example=svc1:8084,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": "", "usa...
Start a pod named 'nginx' with the ubuntu image, but override the specification with a partial set of values parsed from JSON
Command: ```bash kubectl run nginx --image=ubuntu --overrides='{ "apiVersion": "hotfix-1.1.2", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [...
Execute the command "yum install -y aws-cli" inside the first container of the "authentication-service" service
Command: ```bash kubectl exec svc/authentication-service -- yum install -y aws-cli ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If ...
Create a new config map named ui-config using the contents of the profiles folder
Command: ```bash kubectl create configmap ui-config --from-file=path/to/profiles ``` 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...
Start a pod with the specified image, but override some of the spec values using a JSON object.
Command: ```bash kubectl run nginx --image=confluentinc/cp-kafka --overrides='{ "apiVersion": "v1.1.1", "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] [--comm...
Create a new secret named azure-storage-secret using the options.env file as the source of environment variables
Command: ```bash kubectl create secret generic azure-storage-secret --from-env-file=path/to/options.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 ...
Create a cluster role named "admin_role" with ResourceName specified:
Command: ```bash kubectl create clusterrole admin_role --verb=exec --resource=configmaps --resource-name=cache-redis --resource-name=file-uploader ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cl...
Create a new secret named 'api-key-secret' using the parameters from the 'path/to/parameters.env' file
Command: ```bash kubectl create secret generic api-key-secret --from-env-file=path/to/parameters.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 bas...
Set the cluster field in the my-context context to moon-cluster
Command: ```bash kubectl config set contexts.cluster-2-context.cluster moon-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 yo...
Begin streaming the logs of the specified container in the given pod
Command: ```bash kubectl logs -f -c mycontainer web-app-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", "shor...
Create a cluster role named "default_role" with API Group specified
Command: ```bash kubectl create clusterrole default_role --verb=patch,watch,exec --resource=jobs.batch ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--outpu...
Begin streaming the logs of the `astro-container` container in the `auth-service-pod` pod
Command: ```bash kubectl logs -f -c astro-container auth-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...
Copy the local file "/tmp/foo" to the "/etc/kubernetes" directory of the remote pod "kube-flannel/load-balancer-pod-9" in the specified namespace.
Command: ```bash kubectl cp :/tmp/foo kube-flannel/load-balancer-pod-9:/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...
Update the pod named 'chat-app' with the annotation 'compliance-level' and the value 'PCI-DSS'.
Command: ```bash kubectl annotate pods chat-app compliance-level=PCI-DSS ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbi...
Forward local port 6379 to the targetPort of the "https" port in the "monitoring-service" service
Command: ```bash kubectl port-forward service/monitoring-service 6379: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 sel...
Execute the command 'kafka-server-start /etc/kafka/server.properties' in the 'cosmic-container' container within the 'email-service-pod' pod.
Command: ```bash kubectl exec email-service-pod -c cosmic-container -- kafka-server-start /etc/kafka/server.properties ``` 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...
List the pod specified in the "params.yaml" file and display it in YAML format.
Command: ```bash kubectl get -f params.yaml -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only see resul...
Create an ingress configuration called 'app-ingress' that routes requests from foo.com/bar to svc1:8010 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress app-ingress --rule="foo.com/bar=svc1:8010,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": "Out...
Remove all taints with the key 'dedicated' from the node 'db-node-7'
Command: ```bash kubectl taint nodes db-node-7 dedicated- ``` 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...
Attach to a specific container in a pod and interact with it in real time.
Command: ```bash kubectl attach vpn-service-pod -c time-machine -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If om...
Create a pod named hazelcast using the mysql image and expose port 8088.
Command: ```bash kubectl run hazelcast --image=mysql --port=8088 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--fi...
Import the `secret_key` from a config map into the `analytics-platform-deployment`.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-settings deployment/analytics-platform-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 def...
Execute the command 'jenkins-plugin-cli' inside the 'cyber-sleuth' container of the 'backend-pod' pod and retrieve the output.
Command: ```bash kubectl exec backend-pod -c cyber-sleuth -- jenkins-plugin-cli ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omi...
Create a service for the replicated ruby resource, which serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose rc ruby --port=80 --target-port=900000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A d...
Create a copy of the api-service-pod by adding a debug container and changing container images
Command: ```bash kubectl debug api-service-pod -it --copy-to=dgb-img --image=debian --set-image=api=api:v2,mailer=mailer:latest ``` 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. P...
Create a service for the replication controller specified in the "node-controller.yaml" file, serving on port 8010 and connecting to the containers on port 808800.
Command: ```bash kubectl expose -f node-controller.yaml --port=8010 --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 s...
Create a service for the hazelcast replication set called 'hazelcast' with the following configuration:
Command: ```bash kubectl expose rs hazelcast --port=8088 --target-port=700000 ``` 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...
import the keys 'external_api_url' from the 'monitoring-config' config map and set them as environment variables for the 'order-processing-deployment' deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/monitoring-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 var...
Create a new config map named db-config and use the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap db-config --from-file=conf=/path/to/options/file1.txt --from-file=data=/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 creating a config ...