Today I want to show how you can use your local VS Code IDE editor to manage Remote Kubernetes Clusters and connect to running containers, browse local files/folders, and works with MySQL, Redis, ElasticSearch, Debug, and a lot more!
I will skip the part where I wrote one of the possible methods how to connect your kubectl tool to the Remote Kubernetes cluster running in the Cloud or Bare metal servers, and that is already described briefly in the https://nemanja.io/manage-remote-kubernetes-clusters-with-kubectl-and-lens/ article, so please open it now if you need to set up that parts on your local computer.
Please visit the following URL to set up the Remote Kubernetes cluster https://marketplace.visualstudio.com/items?itemName=ms-kubernetes-tools.vscode-kubernetes-tools address or Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
ext install ms-kubernetes-tools.vscode-kubernetes-tools
Once the module is installed, you can click on the left sidebar on the icon and start exploring.
You will notice that Cluster is kubernetes-admin@kubernetes. That is the one you set up using my tutorial with the SSH Tunnel mechanism. This extension has very big documentation of what you can actually do with it from your VS Code editor. Feel free to review https://github.com/vscode-kubernetes-tools/vscode-kubernetes-tools URL. I will cover just the basics of what you need, for example, to connect/attach to a container within a namespace, and one of the best features is "Attach Visual Studio Code" which remotely connects you to the specific container in a separate VS Code window, and you can work there same as you do locally and even install extensions on that container which can be used again next time.
Press CTRL+SHIFT+P keys, then type kubernetes
Select Kubernetes: Use Namespace option and start searching your namespace name, which I assume you already know. You can also explore all namespaces (slower if you have a lot of them) and then search from that area simply by typing keywords.
Once the specific namespace is selected, we can explore everything that Kubernetes offers, like Deployments, Workloads, Secretes, and ConfigMaps. I like this because you can edit something within the YAML file, and with a single click on X, it will check, save, and Kubernetes is going to restart to the latest version. You can also schedule this change for any time that is suitable, close your browser and enjoy your day while the task is going to be scheduled in the Kubernetes.
Deployments --> Workload --> Pods you can simply SSH into any available container within POD, and you will be asked if there are multiple within a single Kubernetes pod.
From the same area right, click, you can do other things like grab logs, describe pod/container or watch it actively while troubleshooting start/stop into a separate window.
Next super feature of this extension is that you can actually "Attach" VS Code IDE server directly into any Kubernetes Pod/Container and remotely connect to it, working from your computer the same way as you do locally. I find this super useful because of many aspects, but I will repeat here few:
- Search is amazing, fast, and accurate
- You can edit any file and parse them with many useful VS Code extensions like a parser, tabnine, or similar
- Smart log extension https://marketplace.visualstudio.com/items?itemName=mbehr1.smart-log
- MySQL/ElasticSearch/Redis browser/editor https://marketplace.visualstudio.com/items?itemName=cweijan.vscode-mysql-client2
You can install anything useful that will help you develop, troubleshoot/debug or test just now with the aspect that you can work from the same place and operate with the Kubernetes cluster.
I hope this article was helpful. Happy DevOpsing :)