Nocalhost provides kubesphere with a more powerful cloud native development environment

Time:2022-5-14

Introduction to the author
Zhang Haili (R & D director of Yushi technology cloud platform): open source enthusiast, PMC member of cloud native community Shanghai station, kubesphere ambassador; Daily cloud native domain work involves kubernetes, Devops, observability, service grid, etc.
Yu Yicai: nocalhost maintainer, CKA, ckad, work from home

Introduction to kubesphere

KubeSphereIt is an application centered multi tenant container platform built on kubernetes, which provides the ability of full stack it automatic operation and maintenance, and simplifies the Devops workflow of the enterprise. ​

Kubesphere provides an operation and maintenance friendly wizard operation interface. Even the inexperienced users of kubernetes can start to manage and use it relatively easily. It provides an application market based on helm, which can easily install various kubernetes applications under the graphical interface. ​

Introduction to nocalhost

NocalhostIt is a tool that allows developers to develop applications directly in the kubernetes cluster.

The core function of nocalhost is to provide nocalhost ide plug-ins (including vscode and JetBrains plug-ins) to change the remote workload to development mode. In the development mode, the image of the container will be replaced with the development image containing development tools (such as JDK, go, python environment, etc.). When developers write code locally, any changes will be synchronized to the remote development container in real time, and the application will be updated immediately (depending on the hot loading mechanism of the application or re running the application). The development container will inherit all the declarative configurations of the original workload (configmap, secret, volume, env, etc.).

Nocalhost also provides:

  • Vscode and JetBrains ide one click debug and hotreload
  • The terminal of the development container is directly provided in the IDE to obtain a consistent experience with local development
  • Provide development space and mesh development space based on namespace isolation

In the process of developing kubernetes application using nocalhost, the process of image construction, updating image version and waiting for the cluster to schedule pod is eliminated, and the code / test / debug feedback cycle is reduced from minute level to second level, which greatly improves the development efficiency.

In addition, nocalhost also provides the server side to help enterprises manage kubernetes applications, developers and development space, which is convenient for enterprises to uniformly manage all kinds of development and testing environments.

Nocalhost provides kubesphere with a more powerful cloud native development environment

This article describes how to deploy quickly in kubesphereNocalhost ServerAnd basic use, providing a management platform to help the R & D team uniformly manage the deployment of nocalhost applications; And the basic use of nocalhost server. ​

prerequisite

Install kubesphere

There are two ways to install kubesphere. First, install directly on Linux. You can refer to the following documents:Installing kubesphere on Linux; Second, install in the existing kubernetes. You can refer to the following documents:Install kubesphere in kubernetes。 ​

Enabling the app store in kubesphere

To enable the app store in kubesphere, refer to the following documents:Kubesphere app store

Installing nocalhost server

Install from the app store in kubesphere 3.2

Nocalhost server has been integrated into the kubesphere 3.2 app store, so you can directly access the app store and pressConventional wayApplication deployment.

Nocalhost provides kubesphere with a more powerful cloud native development environment

In kubesphere 3 Installation through application warehouse in X

In kubesphere 3 In X, you canDeploy applications through the application warehouse, the specific operation process is introduced step by step below.

Step 1: add an app store

First, log in to kubesphere with an account with enterprise space management permission and enter an enterprise space you selected. In your enterprise space, enter the “application warehouse” page under “application management” and click “add warehouse”.Nocalhost provides kubesphere with a more powerful cloud native development environment

In the pop-up dialog box, you can set the application warehouse name tonocalhost, set the URL of the application warehouse tohttps://nocalhost-helm.pkg.coding.net/nocalhost/nocalhost, click “verify” to verify the URL, and then click “OK” after passing the verification.

Nocalhost provides kubesphere with a more powerful cloud native development environment

⚠️ Note: the URL must be pasted with full links and cannot be missinghttps://This part, otherwise the verification will fail

After the application warehouse is imported successfully, it will be displayed in the list shown in the following figure.Nocalhost provides kubesphere with a more powerful cloud native development environment

For more parameter information when adding a private warehouse, seeImport helm warehouse

Step 2: deploy the application from the application template

Enter the project you selected to deploy nocalhost server. If there is no project available, you can directly open the “project” column in the enterprise space page and “create” a new project.Nocalhost provides kubesphere with a more powerful cloud native development environment

Suppose we have created anocalhost-serverEnter the project interface, enter the “application” page under “application load”, and then click “create” new application.Nocalhost provides kubesphere with a more powerful cloud native development environment

Select Create from application template in the pop-up dialog box.Nocalhost provides kubesphere with a more powerful cloud native development environment

  • From the app store: select built-in applications and applications uploaded separately in the form of helm chart.
  • Apply template from: select applications from private application warehouse and enterprise space application pool.

Select the previously added private application warehouse from the drop-down listnocalhost, you can see the nocalhost server helm chart in the warehouse as shown below.Nocalhost provides kubesphere with a more powerful cloud native development environment

You can view “application information” and “chart file”, select the version in the version drop-down list, and then click “deploy”.
Nocalhost provides kubesphere with a more powerful cloud native development environment

Set the “name” of the application, confirm the “version” of the application and the “location” of the deployment, and click “next”.
Nocalhost provides kubesphere with a more powerful cloud native development environment

On the “application settings” tab, you can edit the list file manually or click “Install” directly. It is suggested thatservice.typeSet toClusterIPTo ensure that the installation is not affected by the kubernetes network environment. Of course, you can choose to use it in combination with your own R & D environmentNodePortorLoadBalancerService type to expose nocalhost server (the server itself has no restrictions on this).Nocalhost provides kubesphere with a more powerful cloud native development environment

Finally, wait for the nocalhost server to be created and run. You can see the following application status in “application” (you may need to refresh the page).Nocalhost provides kubesphere with a more powerful cloud native development environment

Step 3: expose nocalhost server service

Enter the “service” page under “application load” and selectnocalhost-webService, select Edit external access from the pull-down menu on the far right.Nocalhost provides kubesphere with a more powerful cloud native development environment

In the pop-up dialog box, select the external network “access method” suitable for the current cloud network environment, and then click “OK” to apply the service configuration.Nocalhost provides kubesphere with a more powerful cloud native development environment

This paper assumes that we still maintainClusterIPThe access method ofkubectl port-forwardFor 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

⚠ Attention: herenocalhost-serverPlease replace with the namespace that you actually used to deploy the nocalhost application

So far, the rapid deployment of nocahost server in kubesphere has been completed. If you are using nocahost server for the first time, you can continue the following contents about the configuration of nocahost server dashboard and the development experience in nocahost ide plug-in.

Using nocalhost server

You can use forward when you are finishedhttp://localhost:8080To open the nocalhost server dashboard page; Use default account[email protected]And password123456Log in.Please change the default password after logging in.

Nocalhost provides kubesphere with a more powerful cloud native development environment

Create cluster

Nocahost server is mostly used to manage the nocahost R & D environment of the whole team, so we need to add manageable clusters first.

In the nocalhost server dashboard, select “cluster” in the menu list on the left, and then select “add cluster” after entering the page.Nocalhost provides kubesphere with a more powerful cloud native development environment

Enter “cluster name” in the pop-up dialog box, and enter the available and qualified information of kubectlcluster-adminClick “confirm” after the kubeconfig file of permission.Nocalhost provides kubesphere with a more powerful cloud native development environment

At present, the contents of the kubeconfig file that can be imported are not supportedexecType of user credentials. If you use the credentials here, it is recommended that you generate another serviceaccount with sufficient permissions and use its corresponding kubeconfig.

There are many 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 kubeconfig file is deployed outside the current cluster, you need toclusters:cluster:serverChange the value of the parameter toExposed kubernetes API server addressNocalhost provides kubesphere with a more powerful cloud native development environmentNocalhost provides kubesphere with a more powerful cloud native development environment

After adding successfully, you can get the following cluster information page.

Nocalhost provides kubesphere with a more powerful cloud native development environment

Create 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.Nocalhost provides kubesphere with a more powerful cloud native development environmentNocalhost provides kubesphere with a more powerful cloud native development environment

“Shared development space”, i.e. meshspace, is beyond the scope of this article. For more information, please refer toManage MeshSpaceThis article introduces.

In the pop-up dialog box, you can fill in “development space name” (set here asdemo), select cluster and its owner, and make other settings as needed.Nocalhost provides kubesphere with a more powerful cloud native development environment

After creation, you can see the created isolated development space on the “development space” page, as shown in the following figure.Nocalhost provides kubesphere with a more powerful cloud native development environment

Create a bookinfo sample application

Next, we start to create some deployable applications for the team. First enter the “application” page and select “add application”.Nocalhost provides kubesphere with a more powerful cloud native development environment

Fill in “application name” in the pop-up dialog box, and we will continue to fill in other information:

  • choiceGitAs “installation source”
  • inputhttps://github.com/nocalhost/bookinfo.gitAs “git warehouse address”
  • choiceManifestAs “manifest type”
  • Leave “application profile” blank to use the default valueconfig.yaml
  • Fill in “relative path of GIT warehouse”manifest/templates

Nocalhost provides kubesphere with a more powerful cloud native development environment

You can visit GitHub to see the completebookinfoSample application warehouse 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 required user information in the pop-up dialog box and “finish” adding.Nocalhost provides kubesphere with a more powerful cloud native development environment

Then we go back to the development space and choose the one we created beforedemoSpace, click the brush icon to enter the “shared users” tab of “Edit development space” and start “add sharing”.Nocalhost provides kubesphere with a more powerful cloud native development environment

Select the user to be added and pay attention to the defaultCooperatorCollaborator permissions, anotherViewerUsers with observer rights can only browse the development space.Nocalhost provides kubesphere with a more powerful cloud native development environment

So far, our configuration in the nocalhost server dashboard has come to an end. Next, we will enter the IDE and use the nocalhost plug-in to implement the application deployment and development experience. ​

Deploy bookinfo application deployment

Here, we will use vs code to deploy applications. First, we need toInstall the nocalhost plug-in in vs Code。 You can also useNocaljets and its plug-ins

Open the nocalhost plug-in panel in vs Code and click+Create a cluster connection, fill in the nocalhost server address, and use the ordinary user created earliertestLogin with your user name and password.Nocalhost provides kubesphere with a more powerful cloud native development environment

If the creation is successful, you can see the development space previously created in the nocalhost server dashboarddemo(nh1btih)
Nocalhost provides kubesphere with a more powerful cloud native development environment

clickdemoThe icon on the top of the vs code editor will be shown on the right, as shown in the icon of the vs code editor before loadingbookinfoApplication.

Nocalhost provides kubesphere with a more powerful cloud native development environment

Selecting this app will launch indemoThe nocalhost application deployment process in the space (select the default branch of the application source for installation). After the installation is completed, the following log and pop-up prompt will appear:Nocalhost provides kubesphere with a more powerful cloud native development environment

At the same time, it can also be expanded in the nocalhost plug-in panelWorkloadSee the specific deployment content.

Nocalhost provides kubesphere with a more powerful cloud native development environment

Development experience

  • Click the green icon to enter the development mode and choose to clone the source code from git warehouse.(when you enter the development mode for the first time, nocahost will prompt you to select the source code directory. You can directly select the local source code directory or clone it locally from the GIT warehouse. Later, nocahost will remember the source code directory and open it directly when you enter the development mode again)
    Nocalhost provides kubesphere with a more powerful cloud native development environment
  • After entering the development mode, nocalhost will automatically replace the workload image with the development image, and synchronize the source code to the remote container.
  • After entering the development mode, a remote container terminal will be opened automatically. Developers can execute commands and run development programs in this terminal.
  • Right click workload authors and click Remote run to run the preset application running commands in the development configuration in the remote container.
    Nocalhost provides kubesphere with a more powerful cloud native development environment
  • After the code is changed and saved, nocalhost automatically synchronizes 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 running command in the remote container again. After changing the code, there is no need to click Remote run again or run the application running command manually)

Remote debugging

  • Right click workload authors and click Remote Debug to enter the remote debug mode.
  • Hit a breakpoint and access it in the browserhttp://127.0.0.1:39080/produc…, you can debug remotely
    Nocalhost provides kubesphere with a more powerful cloud native development environment

Reference link

[1] KubeSphere: https://kubesphere.com.cn/
[2] Nocalhost: https://nocalhost.dev/
[3] Nocalhost Server: https://nocalhost.dev/docs/se…
[4]Installing kubesphere on Linux:https://kubesphere.com.cn/doc…
[5]Installing kubesphere in kubernetes:https://kubesphere.com.cn/doc…
[6]Kubesphere store:https://kubesphere.com.cn/doc…
[7]General method:https://kubesphere.com.cn/doc…
[8]Deploy applications through the application warehouse:https://kubesphere.com.cn/doc…
[9]Import helm warehouse:https://kubesphere.com.cn/doc…
[10] Manage MeshSpace: https://nocalhost.dev/docs/se…
[11] bookinfo: https://github.com/nocalhost/…
[12]To install the nocalhost plug-in in vs Code:https://nocalhost.dev/docs/in…
[13]Nocaljets and its plug-ins:https://nocalhost.dev/docs/in…

Click the link here to open the cloud native development environment

Nocalhost provides kubesphere with a more powerful cloud native development environment