How to edit a kubernetes resource from a shell script

kubectl edit not saving
kubectl edit file in pod
kubectl default editor
kubectl cp
kubectl commands
kubectl exec
kubectl can-i
kubectl restart pod

I went through the documentation to edit kubernetes resource using kubectl edit command. Once I execute the command, the file in YAML-format is opened in the editor where I can change the values as per requirement and save it. I am trying to execute these steps by means of sed. How can the following steps be achieved?

  1. Execute kubectl edit for a deployment resource
  2. Set a value from true to false (using sed)
  3. Save the changes

I tried to achieve this in the following way :

$ kubectl edit deployment tiller-deploy -n kube-system | \
   sed -i "s/\(automountServiceAccountToken:.*$\)/automountServiceAccountToken: true/g"`

Your command is missing a backtick. But even though you put it there, it won't work. The reason is because when you do kubectl edit ..., it edits the file on vim. I am not sure sed would work on vim though. Even though if it does, the output goes to a file, so you get the Vim: Warning: Output is not to a terminal error, which I don't know how to solve.

I would recommend you to get the file and save it. Replace the desired parameters and run it again:

kubectl get deploy tiller-deploy -n kube-system -o yaml > tiller.yaml && sed -i "s/automountServiceAccountToken:.*$/automountServiceAccountToken: true/g" tiller.yaml && kubectl replace -f tiller.yaml

I tried the command above and it worked.

Note: no need to add -n kube-system as the yaml file already contains the namespace.

Managing Resources, This page is an overview of the kubectl command. kubectl - Cheat Sheet Kubectl completion bash) # setup autocomplete in bash into the current shell, bash-​completion Edit any API resource in your preferred editor. Often times you need to inject a configuration file into a container in Kubernetes. This is really easy to do using the ConfigMap resource. But once in a while you might need to inject an executable script into a container. There are any number of reasons why you might need to do so. In my case, I needed to alter the default behaviour of a

I automate through piping the commands through sed command without creating a temporary file. Take the below example, where I am replacing nameserver 8.8.8.8 with 1.1.1.1

$ kubectl -n kube-system get configmap/kube-dns -o yaml | sed "s/8.8.8.8/1.1.1.1/" | kubectl replace -f -

kubectl Cheat Sheet, The edit command allows you to directly edit any API resource you can or EDITOR environment variables, or fall back to 'vi' for Linux or 'notepad' for Windows. To manage a Kubernetes cluster, you use kubectl, the Kubernetes command-line client. If you use Azure Cloud Shell, kubectl is already installed. To install kubectl locally, use the az aks install-cli command: az aks install-cli To configure kubectl to connect to your Kubernetes cluster, use the az aks get-credentials command. This command

I don't know kubectl but doc seems to explain that it extract data, edit from an editor than send back, not sure sed pipe work in this case

if piping wokrs Don't use -i, you don't change a file in a pipe

kubectl edit deployment tiller-deploy -n kube-system | \
 sed 's/automountServiceAccountToken:.*$/automountServiceAccountToken: true/g'

if editing a file (and using group in sed)

kubectl edit deployment tiller-deploy -n kube-system > YourCOnfigFile && \
 sed -i 's/\(automountServiceAccountToken:\).*$/\1 true/g' YourConfigFile \
 && Some kubectl to send back YourConfigFile

kubectl edit, The edit command allows you to directly edit any API resource you can or EDITOR environment variables, or fall back to 'vi' for Linux or 'notepad' for Windows. In the Azure portal, select All resources in the left menu to see the resources created for your new Kubernetes cluster. Recover from a Cloud Shell timeout If the Cloud Shell session times out, you can do the following steps to recover:

kubectl-edit(1) — kubernetes-client, Editing Resources. The edit any API resource in an editor. $ kubectl edit svc/​docker-registry # Edit the service named docker  Note: Cluster Turndown is currently in ALPHA. GKE Setup. We have provided a shell script capable of performing the required steps in setting up a service account for use with cluster-turndown. More info. Running the Setup Script. To use this setup script supply the following parameters:

Kubectl cheatsheet, The edit command allows you to directly edit any API resource you can or EDITOR environment variables, or fall back to 'vi' for Linux or 'notepad' for Windows. Edit This Page. Define a Command and Arguments for a Container. This page shows how to define commands and arguments when you run a container in a Pod A Pod represents a set of running containers in your cluster.. Before you begin. You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with

kubectl-edit - Edit a resource on the server - man page, Get, create, edit, and delete resources with kubectl When using the exec command, the end of the line must always provide which shell you  Edit This Page. Configure Pod Initialization. This page shows how to use an Init Container to initialize a Pod before an application Container runs. Before you begin. You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster.

Comments
  • Please post samples of the Input and expected output in your post too.
  • How should that command ever work?
  • kubectl edit deployment tiller-deploy -n kube-system > YourCOnfigFile would throw an error