头图
About the Author
Haili Zhang (R&D Director of Uisee Technology Cloud Platform): Open source enthusiast, PMC member of the cloud native community Shanghai station, KubeSphere Ambassador; daily work in the cloud native field involves Kubernetes, DevOps, observability, service grid, etc.
Yu Yicai: Nocalhost Maintainer, CKA, CKAD, Work From Home

Introduction to KubeSphere

KubeSphere is an application-centric multi-tenant container platform built on Kubernetes. It provides full-stack IT automated operation and maintenance capabilities and simplifies the DevOps workflow of the enterprise.​

KubeSphere provides an operation and maintenance-friendly wizard-style operation interface, even users who are not experienced in Kubernetes can start management and use relatively easily. It provides a Helm-based application market, which can easily install various Kubernetes applications under a graphical interface.​

Introduction to Nocalhost

Nocalhost is a tool that allows developers to develop applications directly in a Kubernetes cluster.

The core function of Nocalhost is to provide Nocalhost IDE plug-ins (including VSCode and Jetbrains plug-ins) to change remote workloads to development mode. In the development mode, the container image will be replaced with a development image containing development tools (such as JDK, Go, Python environment, etc.). When the developer writes the code locally, any modifications will be synchronized to the remote development container in real time, the application will be updated immediately (depending on the application’s hot-loading mechanism or re-running the application), and the development container will inherit all of the original workload Declarative configuration (configmap, secret, volume, env, etc.).

Nocalhost also provides:

  • VSCode and Jetbrains IDE one-click Debug and HotReload
  • Provide the terminal for developing the container directly in the IDE to get the same experience as the local development
  • Provide development space and Mesh development space based on Namespace isolation

In the process of using Nocalhost to develop Kubernetes applications, the process of mirroring building, updating the mirror version, and waiting for the cluster to schedule Pod is eliminated, and the code/test/debug cycle (code/test/debug cycle) is reduced from the minute level to the second level , Which greatly improves development efficiency.

In addition, Nocalhost also provides a server side to help companies manage Kubernetes applications, developers, and development space, so that companies can manage various development and test environments in a unified manner.

This article will introduce how to quickly deploy Nocalhost Server and provide a management platform that helps R&D teams to uniformly manage the deployment of Nocalhost applications; and basic use of Nocalhost Server.​

Prerequisites

Install KubeSphere

There are two ways to install KubeSphere. One is mounted directly on Linux, refer to the documentation: install KubeSphere in Linux ; the second is installed in an existing Kubernetes, you can refer to the documentation: installed KubeSphere in Kubernetes .​

Enable the app store in KubeSphere

To enable the application store in KubeSphere, please refer to the document: KubeSphere application store .

Install Nocalhost Server

Install from the app store in KubeSphere 3.2

Nocalhost Server has been integrated in the app store KubeSphere 3.2 in, so you can directly access the application store press conventional manner application deployment.

Install through application warehouse in KubeSphere 3.x

In KubeSphere 3.x, you can by application repository to deploy the application , the following steps through the specific operation.

Step 1: Add an app store

First, log in to KubeSphere with an account with enterprise space management permissions and enter an enterprise space you have selected. In your enterprise space, go to the "Application Repository" page under "Application Management" and click "Add Repository".

In the pop-up dialog box, you can set the application warehouse name to nocalhost and the URL of the application warehouse to https://nocalhost-helm.pkg.coding.net/nocalhost/nocalhost . Click "Verify" to verify the URL. After the verification is passed, click "OK".

⚠️ Note: The URL must be pasted with the full link, and the https:// cannot be missing, otherwise the verification will fail

After the application warehouse is imported successfully, it will be displayed in the list as shown in the figure below.

For more parameter information when adding a private warehouse, see Import Helm Warehouse .

Step 2: Deploy the application from the application template

Enter the project you selected for deploying Nocalhost Server. If there is no project available, you can directly open the "Project" column on the corporate space page and "create" a new project.

Suppose we have created a nocalhost-server , enter the project interface, enter the "application" page under "application load", and then click "create" a new application.

In the pop-up dialog box, select "Create from Application Template".

  • from the application store : select the built-in application and the application uploaded separately in the form of Helm Chart.
  • from the application template : select applications from private application warehouses and enterprise space application pools.

Select the previously added private application warehouse nocalhost from the drop-down list, you can see the Nocalhost Server Helm Chart in the warehouse is displayed as follows.

You can view "Application Information" and "Chart File", select the version in the version drop-down list, and then click "Deploy".

Set the application "name", confirm the application "version" and deployment "location", and click "Next".

On the "App Settings" tab, you can manually edit the list file or click "Install" directly. It is recommended to set service.type ClusterIP to ensure that the installation is not affected by the Kubernetes network environment. Of course, you can choose to use the NodePort or LoadBalancer service type to expose Nocalhost Server in combination with your own R&D environment (the Server itself has no restrictions on this).

Finally, wait for Nocalhost Server to be created and start running. You can see the following application status in "Applications" (you may need to refresh the page).

Step 3: Expose the Nocalhost Server service

nocalhost-web to the "Service" page under "Application Load", select the 061adc30b269a4 service, and select "Edit External Access" from the pull-down menu on the far right.

In the pop-up dialog box, select the "Access Method" of the external network suitable for the current cloud network environment, and then click "OK" to apply the service configuration.

This article assumes that we remain ClusterIP access method by kubectl port-forward to subsequent Nocalhost Server use.

❯ kubectl -n nocalhost-server port-forward service/nocalhost-web 8080:80
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
⚠️ Note: nocalhost-server here with the Namespace you are actually using to deploy the Nocalhost application

At this point, the rapid deployment of Nocalhost Server in Kubesphere has been completed. If you are using Nocalhost Server for the first time, you can continue with the following about Nocalhost Server Dashboard configuration and development experience in the Nocalhost IDE plug-in.

Use Nocalhost Server

After completing Port Forward, you can use http://localhost:8080 to open the Nocalhost Server Dashboard page; use the default account admin@admin.com and password 123456 to log in. Please change the default password after logging in.

Create a cluster

Nocalhost Server is mostly used to manage the Nocalhost R&D environment of the entire team, so we first need to add a manageable cluster.

In Nocalhost Server Dashboard, select "Cluster" in the menu list on the left, and select "Add Cluster" after entering the page.

Enter the "cluster name" in the pop-up dialog box, and enter the kubeconfig file available for with 161adc30b26b9a cluster-admin permissions and "confirm".

The content of the kubeconfig file that can be imported currently does not support exec . If you use this credential, it is recommended that you generate a ServiceAccount with sufficient permissions and use its corresponding kubeconfig.

There are multiple ways to obtain the kubeconfig of the target cluster. For example, you can return to KubeSphere and enter the cluster page to obtain the kubeconfig file of the current cluster. Note that if the application using the kubeconfig file is deployed outside the current cluster, you need to clusters:cluster:server the value of the exposed Kubernetes API server address .

After successful addition, you can get the following cluster information page.

Create a development space (DevSpace)

Next, we enter the "Development Space" page, select "Create Development Space", and select "Create Isolated Development Space" in the pop-up dialog box.

"Shared development space", namely MeshSpace, is not in the scope of this article. For more information, please refer to Manage MeshSpace .

In the pop-up dialog box, you can fill in the "development space name" (here set to demo ), select "cluster" and its "owner", and perform "other settings" as needed.

After the creation is complete, you can see the created isolated development space on the "Development Space" page, as shown in the figure below.

Create bookinfo sample application

Next, we start to create some deployable applications for the team. First enter the "Applications" page and select "Add Application".

Fill in the "application name" in the pop-up dialog box, while we continue to fill in other information:

  • Select Git as the "installation source"
  • Enter https://github.com/nocalhost/bookinfo.git as the "Git Warehouse Address"
  • Select Manifest as the "Manifest Type"
  • Leave "Application Configuration File" blank, that is, use the default value config.yaml
  • "Relative path to Git repository" fill in manifest/templates

can visit GitHub to view the complete bookinfo sample application repository for detailed configuration file details.

Create users and share development space

Finally, we create a sample user to demonstrate how to share the development space. After entering the "User" page, click "Add User", fill in the necessary user information in the pop-up dialog box and "Finish" the addition.

Then we return to the development space, select the demo space we created earlier, click the pen icon to enter the "shared user" tab of the "edit development space", and start "add sharing".

Select the user that needs to be added, and pay attention to selecting the default Cooperator collaborator authority. Another Viewer observer authority of 061adc30b26f0f can only browse the development space.

At this point, our configuration in Nocalhost Server Dashboard has come to an end. Next, we will enter the IDE and use the Nocalhost plug-in to perform application deployment and development experience.​

Deploy bookinfo application deployment

Here we will use VS Code to perform application deployment. First, we need to install Nocalhost plug-in . You can also use JetBrains and its Nocalhost plug-in .

Open the Nocalhost plug-in panel in VS Code, click + to create a cluster connection, fill in the Nocalhost Server address, and test with the user name and password of the ordinary user 061adc30b26fcd created earlier.

Successful creation can see the development space demo(nh1btih) created in Nocalhost Server Dashboard before.

Click demo space, and the application list will be loaded on the top of the VS Code editor. As shown in the figure below, you can see the previously added bookinfo application.

Selecting the application will start demo space (select the default branch of the application source to install). After the installation is complete, the following log and pop-up prompt will appear:

At the same time, you can also expand Workload in the Nocalhost plug-in panel to see the specific deployment content.

Development experience

  • Click the green icon to enter the development mode and choose to clone the source code from the git repository. (When you enter the development mode for the first time, Nocalhost will prompt you to select the source directory, you can directly select the local source directory, or you can choose to clone from the git repository to the local, and then Nocalhost will remember the source directory. When you enter the development mode again, it will Open this source directory directly)
  • After entering the development mode, Nocalhost will automatically replace the image of the workload with the development image, and synchronize the source code to the remote container.
  • After entering the development mode, a remote container terminal is automatically opened, and developers can execute commands and run development programs in this terminal.
  • Right-click the workload authors and click Remote run to run the application running commands preset in the development configuration in the remote container.
  • After the code is changed and saved, Nocalhost will automatically synchronize the changed code file to the remote container. (If the hotReload: true parameter is configured in the development configuration, nocalhost will automatically run the preset application run command again in the remote container. After changing the code, there is no need to click Remote run again or manually run the application run command)

Remote debugging

Reference link

[1] KubeSphere: https://kubesphere.com.cn/
[2] Nocalhost: https://nocalhost.dev/
[3] Nocalhost Server: https://nocalhost.dev/docs/server/server-overview
[4] Install KubeSphere on Linux: ">https://kubesphere.com.cn/docs/quick-start/minimal-kubesphere-on-k8s/
[6] KubeSphere App Store: ">https://kubesphere.com.cn/docs/project-user-guide/application/deploy-app-from-appstore/
[8] Deploy applications through application warehouse: ">https://kubesphere.com.cn/docs/workspace-administration/app-repository/import-helm-repository/
[10] Manage MeshSpace: https://nocalhost.dev/docs/server/manage-devspace-mesh
[11] bookinfo: https://github.com/nocalhost/bookinfo/
[12] Install the Nocalhost plugin in VS Code: ">https://nocalhost.dev/docs/installation#install-jetbrains-plugin

Click here to open the cloud native development environment with one


CODING
3.3k 声望4k 粉丝

CODING 是腾讯云旗下一站式 DevOps 研发管理平台,向广大开发者及企业研发团队提供代码托管、项目协同、测试管理、持续集成、制品库、持续部署、云原生应用管理 Orbit、团队知识库等系列工具产品,支持 SaaS 模式...