用于 Kubernetes 迭代开发的 Rust 和 Skaffold

迭代开发要求能够快速构建/推送/部署。这些任务在原生云环境中不容易实现,但值得努力以使这些功能实现自动化。能够看到他们所做的努力引发的改变,将极大地提升开发人员的开发速度。在本课题中,我们将展示如何远程地将服务自动化构建并推送到一个 Kubernetes 集群上,从而允许快速迭代。 我们将使用 Rust 从头开发 REST 服务。此项服务将部署到 Kubernetes,并通过使用 Skaffold 实现持续部署。 这个演示将分步骤进行,首先是一个非持久性的简单网络服务器,之后在 Kubernetes 部署中添加一个 DB,并使用 Diesel 来连接它。在此期间,Skaffold 将用于在我们工作时对 K8 集群上“显现”的更改进行无缝监视。
展开查看详情

1.Rust and Skaffold for Iterative Development on Kubernetes

2.宋子豪 Gilbert Song Staff Software Engineer ● Apache Mesos PMC/Committer ● Leading Containerization at Mesosphere ● Twitter: @gilbert_songs

3.Gastón Kleiman Staff Software Engineer ● Apache Mesos PMC/Committer ● Resource Management Tech Lead at Mesosphere ● Previously at AWS OpsWorks ● Twitter: @kleimang

4.Outline Modern development techniques Iterative Development CI/CD Immutable infrastructure + Containers Challenges Tools Rust, Kubernetes, Skaffold Demo 4

5.Continuous/Iterative Development • Design, develop, and test in repeated cycles • Testing a new iteration must be quick & cheap 5

6.Continuous Integration/Continuous Deployment • Automated testing as well as deployment of a web application • Containers make it possible to replicate the same environment during development and in production 6

7.Pets -> Cattle -> Immutable Infrastructure 7

8.Challenges • Building, pushing, and deploying isn’t easy • Giant binaries/containers • Applications need to be safe (concurrency + memory safety) 8

9.Rust • Created at Mozilla as a “safe, concurrent, practical language” • Low-level (static) language, performance similar to C++ • Strong emphasis on safety, control of the memory layout, concurrency • Great & friendly community 9

10.Challenges with Rust • Relatively young language • Brings extra safety, but you have to pay some upfront price • Many engineers are new to it; successfully integrating it into your stack can cost significant engineering time 10

11.Kubernetes • Orchestrates containers across many different machines… or on your local dev machine • Enables you to use immutable infrastructure • Useful abstractions/tools to easily deploy or scale services • DC/OS Multi-Kubernetes-Engine 11

12.Skaffold • CLI tool that facilitates iterative development for Kubernetes applications • Handles the workflow for building, pushing, and deploying an application • Can be used to iterate on an application source code locally then deploy to local or remote Kubernetes clusters 12

13.Skaffold Build Push Deploy

14.Skaffold (Local) Build Push Deploy Local Docker None Minikube Daemon 14

15.Skaffold (Remote) Build Push Deploy Google Docker Registry Container MKE on DC/OS on DC/OS Builder 15

16.Using Skaffold No need to have each new developer spend days setting up a new dev environment 1. Create k8s manifests (pod specs, ingress settings, etc) 2. Tell skaffold via skaffold.yaml how to build and deploy the application 3. Use “skaffold dev” on your local machine to deploy to a minikube cluster 4. Make your CI/CD pipeline run “skaffold run” when new code is checked-in 16

17.Demo Flow Skaffold Save Trigger Build Push Deploy Push 17

18.Demo 18

19.Future Work • Make the service highly-available: • Use an HA posgres setup • Zero-downtime deployments • Utilize more of the dependencies’ capabilities and increase efficiency: • Use connection pools for Diesel • Use Rocket managed state 19

20.Resources • Mesosphere Kubernetes Engine (MKE) - https://mesosphere.com/product/kubernetes-engine/ • https://github.com/shaneutt/dcos-k8s-rust-skaffold-demo 20

21.Special Thanks Shane Utt Jörg Schad 21

22. THANK YOU! ANY QUESTIONS? https://mesosphere.com/resources/running-kubernet es-oreilly-ebook/ © 2018 Mesosphere, Inc. All Rights Reserved. 22

23. Make it insanely easy to build and scale world-changing technology CONFIDENTIAL