Movatterモバイル変換


[0]ホーム

URL:


TryMCP servers to extend agent mode in VS Code!

Dismiss this update

Working with Kubernetes in VS Code

This document will walk you through the process of deploying an application toKubernetes with Visual Studio Code.Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. We will show you how to create a Kubernetes cluster, write a Kubernetes manifest file (usually written in YAML), which tells Kubernetes everything it needs to know about the application, and then finally deploy the application to the Kubernetes cluster.

Before you begin

You will need to have tools forDocker andkubectl. See theInstall Docker documentation for details on setting up Docker on your machine andInstall kubectl. Before proceeding further, verify you can run Docker and kubectl commands from the shell.

You can create a local Kubernetes cluster withminikube or an Azure Kubernetes cluster inAzure Kubernetes Service (AKS). In this tutorial, we will useAzure Kubernetes Service (AKS) and you will need to have yourAzure account ready for the deployment steps.

Install the Kubernetes extension

For a fully integrated Kubernetes experience, you can install theKubernetes Tools extension, which lets you quickly develop Kubernetes manifests and HELM charts. With the extension, you can also deploy containerized micro-service based applications to local or Azure Kubernetes clusters and debug your live applications running in containers on Kubernetes clusters. It also makes it easy to browse and manage your Kubernetes clusters in VS Code and provides seamless integration withDraft to streamline Kubernetes development.

To install the Kubernetes extension, open the Extensions view (⇧⌘X (Windows, LinuxCtrl+Shift+X)) and search for "kubernetes". Select the MicrosoftKubernetes extension.

Install Kubernetes

Containerize and publish the application

You can follow theWorking with Docker tutorial to build your project, generate a Docker image, and push it to a public or private container registry through the MicrosoftContainer Tools Extension.

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 seeKUBERNETES in the Explorer. Click onMore and chooseCreate Cluster. Follow the instructions to choose the cluster type (here we chooseAzure Kubernetes Service), select your subscription, and set up the Azure cluster and Azure agent settings. It will take a few minutes to complete the whole workflow.

Create Kubernetes

Important: To create a Kubernetes cluster on Azure, you need to install theAzure CLI and sign in.

Tip: You will encounter an error if you don't have an available RSA key file. Followcreate SSH public-private key to create your key before creating an Azure Kubernetes cluster.

Error with RSA

Tip: You might encounter an error indicating conflicting location and VM size when creating an Azure Kubernetes cluster. Pay attention to choose proper location and VM size.

Error creating cluster

Deploy the application to Azure Kubernetes Service

The Kubernetes extension provides autocompletion, code snippets, and verification for the Kubernetes manifest file. For example, once you type 'Deployment' in an empty YAML file, a manifest file with fundamental structure is autogenerated for you. You only need to enter your app name, image, and port manually.

Create manifest

Below is an example manifest file:

Manifest example

Once your manifest file is ready, you only need one command to start a deployment. Open theCommand Palette (⇧⌘P (Windows, LinuxCtrl+Shift+P)) and runKubernetes: Create. It will deploy the application to your Kubernetes cluster and create objects according to the configuration in the open Kubernetes manifest file.

Start deployment

Checking on your deployment

After deployment, the Kubernetes extension can help you check the status of your application. From the Explorer, click onWorkloads, right click onPods and then chooseGet to see whether the application has started. To view the status of your app, selectServices, right click on your app, and then clickGet. The status will be printed to the Integrated Terminal. Once your application has anEXTERNAL_IP, you can open a browser and see your web app running.

Check status

Congratulations! Now your app is successfully running in Azure Kubernetes Service!

Next steps

  • Azure Extensions - The VS Code Marketplace has hundreds of extensions for Azure and the cloud.
  • Deploying to Azure - Learn step-by-step how to deploy your application to Azure.
5/4/2022

[8]ページ先頭

©2009-2025 Movatter.jp