Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to edit codes in kubernetes pods using VS Code?

Typically, if I have a remote server, I could access it using ssh, and VS Code gives a beautiful extension for editing and debugging codes for the remote server. But when I create pods in Kuberneters, I can't really ssh into the container and so I cannot edit the code inside the pod or machine. And the kuberneters plugin in VSCode does not really help because the plugin is used to deploy the code. So, I was wondering whether there is a way edit codes inside a pod using VSCode.

P.S. Alternatively if there is a way to ssh into a pod in a kuberneters, that will do too.

like image 707
user3086871 Avatar asked Oct 29 '19 04:10

user3086871


People also ask

How do I edit a file in Kubernetes pod?

There are two ways to edit a file in an existing pod: either by using kubectl exec and console commands to edit the file in place, or kubectl cp to copy an already edited file into the pod.

How do I edit in Kubernetes?

Edit a PODRun the kubectl edit pod <pod name> command. This will open the pod specification in an editor (vi editor). Then edit the required properties. When you try to save it, you will be denied.

How do I connect Visual Studio code to Kubernetes?

Create and config a Kubernetes cluster You can create a Kubernetes cluster running on Azure using the Kubernetes extension in VS Code. Once you have installed the Kubernetes extension, you will see KUBERNETES in the Explorer. Click on More and choose Create Cluster.


2 Answers

If your requirement is "kubectl edit xxx" to use VSCode.

The solution is:

  • For Linux: export EDITOR='code --wait'

  • For Windows: set EDITOR=code --wait

  • For macOS: export EDITOR='open -a "Visual Studio Code" --wait'

like image 124
Hlex Avatar answered Oct 03 '22 05:10

Hlex


Kubernetes + Remote Development extensions now allow:

  • attaching to k8s pods
  • open remote folders
  • execute remotely
  • debug on remote
  • integrated terminal into remote

vscode attaching to k8s pod

must have:

  • kubectl
  • docker (minimum = docker cli - Is it possible to install only the docker cli and not the daemon)

required vscode extentions:

  • Kubernetes. https://marketplace.visualstudio.com/items?itemName=ms-kubernetes-tools.vscode-kubernetes-tools
  • Remote Development - https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack
like image 20
Pav K. Avatar answered Oct 03 '22 04:10

Pav K.