In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
In this issue, the editor will bring you what are the three tools to achieve rapid K8S development. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
Brief introduction
Today, Kubernetes is becoming more and more important. Not only do operators need Kubernetes, but Kubernetes is also indispensable in the development world. Therefore, being able to master the knowledge of Kubernetes will be highly sought after. The question, however, is whether developers need to get started with Kubernetes, and whether they must fully understand Kubernetes.
A common way to avoid this problem is to abstract the complexity of Kubernetes from developers by providing a platform or CI/CD pipeline, making it easier for developers to test applications within Kubernetes without having to access Kubernetes directly.
However, it often makes sense to allow developers to access Kubernetes directly and let them develop applications directly within Kubernetes, because it works in an environment that is very close to production.
This raises the question of how to get developers to work with Kubernetes without being overwhelmed by its complexity. The answer to this question may be to use a developer tool for Kubernetes, such as DevSpace. In this article, we will explore how developers can use DevSpace and Rancher to simplify Kubernetes development.
DevSpace: easy development with Rancher
DevSpace is a client-side, open source developer tool for Kubernetes. It can:
Build, test, and debug applications directly within Kubernetes
Hot reload development by updating the running container without rebuilding the image or restarting the container
Unified deployment of workflows within the team as well as in development, staging, and production
Automate the repetitive tasks of image construction and deployment
As a client tool for developers, DevSpace is a supplement to Rancher. Developers get assigned projects within Rancher and then develop or test applications directly within Kubernetes. This brings the development environment closer to the production environment and gives developers more confidence when releasing new features, believing that everything will work well in the production environment.
Set up DevSpace
First you need to download the DevSpace binaries, and next, create a new project by running devspace init in an already containerized project. If you don't have a pilot project on hand, you can use our example project:
Https://devspace.sh/cli/docs/getting-started/initialize-project#choose-a-project
$devspace init _ _ _) | | _) | (_ |) | (_ | _ /\ _ | _ / |. _ _ /\ _ _ |\ _ | | _ |? How do you want to initialize this project? Use the Dockerfile in. / Dockerfile? Which registry do you want to use for storing your Docker images? Use hub.docker.com = > you are logged in as devspacecloud? Which image name do you want to use on Docker Hub? Devspacecloud/quickstart? Which port is your application listening on? (Enter to skip) 8080 [done] √ Project successfully initialized
After you have answered a few questions about the project that should be initialized, DevSpace will create a devspace.yaml for you. This file contains how to deploy and develop a project using DevSpace, which looks like this:
Version: v1beta9# This section defines the images that should be builtimages: app: image: devspacecloud/quickstart preferSyncOverRebuild: true # this option tells devspace to automatically wrap the Dockerfile entrypoint in memory # with a small restart helper script so that the process can be easily restarted from within the # container. InjectRestartHelper: true# Defines an array of everything (component, Helm chart Kubernetes maninfests) # that will be deployed with DevSpace in the specified orderdeployments:- name: quickstart helm: # Uses a special helm chart provided by devspace to complement projects that don't have an own # helm chart componentChart: true values: containers:-image: devspacecloud/quickstart service: ports:-port: 808 Configuration that will be used for developing the applicationdev: # Port forward certain ports from the application to the local computer ports:-imageName: app forward: -port: 8080 # Hot reload changes instead of rebuilding the complete docker image all the time sync:-imageName: app # This tells devspace to restart the container after a file was synced into it onUpload: restartContainer: trueprofiles:...
Now, you can share this configuration across teams. It specifies how to develop applications independently of local settings within Kubernetes.
To start developing applications, you need to access a Kubernetes cluster or Rancher project. The best practice is to create a Rancher project for each developer or a single project for a team of developers within a shared cluster.
To ensure simple isolation between different projects and namespaces, use common Kubernetes resources such as Resource Quotas, network policy, Pod security policy, and Limit Ranges.
Use DevSpace to develop applications
Run the command devspace.dev to start the development process. This will do the following:
Build and deploy your application
Streaming all container logs deployed during deployment
Forward all ports specified by dev.ports in devspace.yaml
Synchronize all file changes according to the synchronization configuration in dev.sync, so you can restart the application in the running container without rebuilding the image or redeploying anything
$devspace dev-n test [info] Using kube context 'docker-desktop' [info] Using namespace' test' [done] √ Created namespace: test [info] Building image 'myusername/devspace:C5992q4' with engine' docker'Step 1 prime 7: FROM node:13.12-alpine... [done] √ Done processing image 'myusername/devspace' [done] √ Deployed helm chart (Release revision: 0) [done] √ Successfully deployed quickstart with helm [done] √ Port forwarding started on 3000 Done] √ Sync started on / devspace/examples/quickstart. (Pod: test/quickstart-5d7f4d8fd-w95cx) # [info] DevSpace UI available at: http://localhost:8090#################################### # [info] Starting log streaming for containers that use images defined in devspace.yaml [quickstart] [quickstart] > node-js-sample@0.0.1 start / app [quickstart] > nodemon index.js [quickstart] [quickstart] [nodemon] 1.19.4 [quickstart] [nodemon] to restart at any time Enter `rs` [quickstart] [nodemon] watching dir (s): *. * [quickstart] [nodemon] watching extensions: js,mjs,json [quickstart] [nodemon] starting `node index.js` [quickstart] Example app listening on port 3000!
After you modify the file locally, the file is synchronized to the container. After the container is restarted, there is no need to completely rebuild through Docker, which greatly speeds up the development process.
DevSpace then launches a local UI, and you can access and check the created pod. This simplifies interaction with Kubernetes, especially for users who are not familiar with kubectl.
Except that the devspace dev,devspace deploy command can be used to package and deploy applications without hot reloading, port forwarding, or log flow. DevSpace provides a number of custom features to adjust its behavior to your use cases and settings, including:
Dependencies that allow you to develop and deploy projects that depend on other projects
Profiles, which can be configured in a single devspace.yaml
Variables that allow you to specify dynamic configuration values
Commands that allow you to configure custom commands for a project
Hooks that can perform certain functions on specific DevSpace events
Environment variables that automatically add flags (flag) to the devspace command
Plug-ins that extend DevSpace and its commands
While DevSpace standardizes and simplifies the way developers interact with Kubernetes, Rancher manages how developers work within Kubernetes on the server side. Rancher allows you to start development clusters and divide them into different projects where development teams can work and test together.
In addition to the common Kubernetes isolation resources, Resource Quotas projects can also constrain the team in terms of resources, so that the team can be used fairly in a shared Kubernetes cluster. Sharing Kubernetes clusters reduces infrastructure overhead and allows efficient development directly within Kubernetes.
Building blocks for rapid development: loft
Loft is another useful tool that can add some convenient features to the development process, including:
Virtual clusters, which are cheaper than "real" clusters, can be created and cleaned up again in seconds, and are more powerful than simple namespaces
Self-service of providing namespaces for developers in a shared cluster (self-service)
Sleep mode, which puts the namespace to sleep after being inactive for a certain period of time to save computational cost
You can easily add loft to Rancher by installing loft helm chart. Loft CLI can also be used as a plug-in for DevSpace.
These are the three tools that Xiaobian shared for you to achieve rapid K8S development. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.