arduino joy
Let’s face it: Developing distributed applications is painful.
讓我們面對現實:開發分布式應用程序很痛苦。
Microservice architectures might be great for decoupling and scalability but they are intimidatingly complex when it comes to development.
微服務體系結構可能對解耦和可伸縮性非常有用,但在開發方面它們卻極其復雜。
Local Kubernetes clusters (Minikube), long build times (Docker), and awkward or even nonexistent solutions to debugging is how we started. Two years in, we have automated everything: nothing runs on my local machine anymore and I can start coding and debugging individual components on any branch in just 15 seconds. 🎉
我們是從本地Kubernetes集群(Minikube),較長的構建時間(Docker)以及笨拙甚至不存在的調試解決方案開始的。 兩年以來,我們已實現了一切自動化:不再在本地計算機上運行任何東西,而且我可以在15秒內開始對任何分支上的單個組件進行編碼和調試。 🎉
I now enjoy working on our project so much and believe this is one of the most streamlined setups out there. In the following I want to share that experience.
我現在非常喜歡我們的項目,并且相信這是目前最簡化的設置之一。 在下文中,我想分享這一經驗。
從預覽環境開始 (Starting with a Preview Environment)
To get started on a bugfix or feature, I just need to create a new branch on GitHub. This will immediately trigger our CI servers (we use Jenkins) which then deploys a preview application to a GKE cluster. The application lives in a namespace corresponding to the branch name and, using the preview URL, I can access and use the application.
要開始使用錯誤修正或功能,我只需要在GitHub上創建一個新分支即可。 這將立即觸發我們的CI服務器(我們使用Jenkins),然后將預覽應用程序部署到GKE集群。 該應用程序位于與分支名稱相對應的名稱空間中,并且可以使用預覽URL訪問和使用該應用程序。
Since I only branched off and didn't push any changes, the build artifacts are cached and the deployment takes only a few seconds. But even once I push changes, the build will run quickly as it only rebuilds what is really necessary.
由于我只是分支機構,沒有進行任何更改,因此將緩存構建工件,并且部署僅需幾秒鐘。 但是,即使我推送更改,構建也將快速運行,因為它僅重建真正需要的內容。
開始編碼 (Starting to Code)
Next up I spin up a development environment to work on my task. We use Gitpod, which similarly to a CI server prebuilds dev environments for any branch. A click on a button from any of our project’s GitHub pages starts a fresh dev environment for exactly that branch and opens it in my browser.
接下來,我啟動了一個開發環境來完成我的任務。 我們使用Gitpod ,它類似于CI服務器為任何分支預先構建開發環境。 在我們項目的GitHub頁面的任何一個上單擊按鈕,即可為該分支完全打開一個全新的dev環境,并在我的瀏覽器中將其打開。
The dev environment is up after ~15secs and awaits me with a fresh clone of our repo and the correct branch checked out. Furthermore, the project is fully built and even all dependencies are downloaded already. The terminal welcomes me with the following message:
大約15秒后,開發環境就啟動了,并等待我們重新克隆我們的repo并簽出正確的分支。 此外,該項目已完全構建,甚至所有依賴項都已下載。 終端歡迎我以下消息:
The IDE is preconfigured with all the VS Code extensions we need, in our case Kubernetes, Docker, MySQL, Go and TypeScript. It is also already connected to the Kubernetes cluster running the preview environment as well as the corresponding database. So I can, for example, type 'kubectl get all' in my terminal and see all the deployed kube objects.
IDE已預先配置了我們所需的所有VS Code擴展,例如Kubernetes,Docker,MySQL,Go和TypeScript。 它也已經連接到運行預覽環境的Kubernetes集群以及相應的數據庫。 因此,例如,我可以在終端中鍵入“ kubectl get all”并查看所有已部署的kube對象。
The connection is based on a secret token that every developer has to put into their user account once and which is injected when starting a dev environment.
該連接基于一個秘密令牌,每個開發人員都必須將其放入用戶帳戶一次,并在啟動開發環境時將其注入。
Although these ephemeral dev environments run in my browser, they provide all the state-of-the-art tools, allowing me to code, compile, run and debug code as well as interact with the database and the cluster.
盡管這些短暫的dev環境在我的瀏覽器中運行,但是它們提供了所有最新的工具,使我能夠進行代碼編寫,編譯,運行和調試代碼以及??與數據庫和集群進行交互。
Of course, I can now push any of my code changes to GitHub and wait for the CI to update my preview environment accordingly. Since the build is caching heavily, small changes are deployed in a minute or so. Most of the time, however, a minute is way too long. We need an instant, hot-reloading experience that allows to debug any service in the context of the full application. Enter Telepresence.
當然,我現在可以將任何代碼更改推送到GitHub,然后等待CI相應地更新我的預覽環境。 由于構建會大量緩存,因此一分鐘左右即可部署少量更改。 但是,大多數情況下,一分鐘太長了。 我們需要即時的熱重裝體驗,以便可以在整個應用程序的上下文中調試任何服務。 輸入網真 。
使用網真進行調試 (Debugging with Telepresence)
I want to be able to debug any individual service in the context of the full application. Instead of waiting for redeploys, our components have proper launch configs to debug them using Telepresence.
我希望能夠在整個應用程序的上下文中調試任何單個服務。 我們的組件無需等待重新部署,而是擁有適當的啟動配置,可以使用Telepresence對其進行調試。
Telepresence replaces a Kubernetes deployment with a proxy that forwards all communication to a locally running process. So in short I can start a local debug session and have it working in the context of my preview environment.
網真用代理將Kubernetes部署替換為代理,該代理將所有通信轉發到本地運行的進程。 簡而言之,我可以啟動本地調試會話,并使其在預覽環境中正常工作。
This works fantastically and is the best way I’ve seen so far for debugging Kubernetes services. It allows me to reuse all the existing debugging tools available.
這工作得非常好,是迄今為止到目前為止調試Kubernetes服務的最佳方式。 它允許我重用所有可用的現有調試工具。
推送和審查 (Pushing and Review)
Once I’m happy with my changes, I push to my branch and create a Pull Request. I can do that from within Gitpod which is quite convenient.
對更改感到滿意后,我將推送到分支并創建“拉取請求”。 我可以在Gitpod中完成此操作,這非常方便。
Jenkins will now update the preview environment and Gitpod prebuilds a new dev environment. So when a colleague wants to start reviewing my changes, they can try them out immediately and quickly launch a dev environment for deeper inspection. From within Gitpod they can add comments to the code and even approve (or reject) the PR.
Jenkins現在將更新預覽環境,而Gitpod將預先構建一個新的開發環境。 因此,當一位同事希望開始查看我的更改時,他們可以立即嘗試這些更改并快速啟動開發環境以進行更深入的檢查。 他們可以從Gitpod內部向代碼添加注釋,甚至批準(或拒絕)PR。
結論 (Conclusion)
Achieving fast turnarounds and automated setups for distributed applications is hard but an absolute necessity for getting into a productive flow. Any friction in this will have a bad effect on the productivity of your team.
實現分布式應用程序的快速周轉和自動設置是困難的,但是絕對需要進入生產流程。 任何摩擦都會對您團隊的生產力產生不良影響。
A fast build with preview environments and the slick Telepresence-based debugging experience have been an enjoyable productivity boost for us. If Gitpod didn’t exist we’d have to build it ;).
快速的預覽環境構建和出色的基于網真的調試經驗為我們帶來了令人愉悅的生產力提升。 如果Gitpod不存在,則必須構建它;)。
Do you have questions? Reach out, we are happy to help.
你有問題嗎? 伸出援助之手 ,我們很樂意提供幫助。
Note: Some of the features in Telepresence require system calls that are currently only allowed in Gitpod self-hosted.
注意:網真中的某些功能需要系統調用,當前僅在Gitpod自托管中才允許。
翻譯自: https://www.freecodecamp.org/news/developing-kubernetes-applications-with-joy/
arduino joy