ToB企服应用市场:ToB评测及商务社交产业平台

标题: Pulumi才是未来底子设施的赢家 [打印本页]

作者: 兜兜零元    时间: 2024-6-11 08:34
标题: Pulumi才是未来底子设施的赢家


  

一、前言


二、什么是Pulumi


三、Pulumi Vs Terraform

3.1、两者渊源


3.2、两者区别




四、快速入门Pulumi


4.1、Pulumi支持的Provider





4.2、利用发起



4.3、利用示例(TypeScript)

4.3.1、安装 Pulumi


  1. curl -fsSL https://get.pulumi.com | sh
复制代码
4.3.2、项目管理方式


4.3.3、创建新项目(Kubernetes Provider)


  1. # 以自托管方式为例 :
  2. # 创建本地目录
  3. mkdir pulumi-typescript && cd pulumi-typescript
  4. # 登录到本地目录
  5. pulumi login file:///Users/daizhe/Desktop/myself/pulumi-typescript
  6. # 检查登录的用户
  7. pulumi whoami -v
  8. User: daizhe
  9. Backend URL: file:///Users/daizhe/Desktop/myself/pulumi-typescript
  10. warning: A new version of Pulumi is available. To upgrade from version '3.10.3' to '3.54.0', run
  11.    $ brew upgrade pulumi
  12. or visit https://pulumi.com/docs/reference/install/ for manual instructions and release notes.
  13. # Pulumi New Kubernetes Provider交互填写名称和项目描述
  14. pulumi new kubernetes-typescript
  15. This command will walk you through creating a new Pulumi project.
  16. Enter a value or leave blank to accept the (default), and press <ENTER>.
  17. Press ^C at any time to quit.
  18. project name: (pulumi-typescript)
  19. project description: (A minimal Kubernetes TypeScript Pulumi program)
  20. Created project 'pulumi-typescript'
  21. stack name: (dev)
  22. Created stack 'dev'
  23. Installing dependencies...
  24. added 165 packages in 16s
  25. npm notice
  26. npm notice New major version of npm available! 8.13.0 -> 9.4.2
  27. npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.4.2
  28. npm notice Run npm install -g npm@9.4.2 to update!
  29. npm notice
  30. Finished installing dependencies
  31. Your new project is ready to go! ✨
  32. To perform an initial deployment, run 'pulumi up'
  33. warning: A new version of Pulumi is available. To upgrade from version '3.10.3' to '3.54.0', run
  34.    $ brew upgrade pulumi
  35. or visit https://pulumi.com/docs/reference/install/ for manual instructions and release notes.
复制代码
4.3.4、查看新项目


  1. import * as k8s from "@pulumi/kubernetes";
  2. import * as kx from "@pulumi/kubernetesx";
  3. const appLabels = { app: "nginx" };
  4. const deployment = new k8s.apps.v1.Deployment("nginx", {
  5.     spec: {
  6.         selector: { matchLabels: appLabels },
  7.         replicas: 1,
  8.         template: {
  9.             metadata: { labels: appLabels },
  10.             spec: { containers: [{ name: "nginx", image: "nginx" }] }
  11.         }
  12.     }
  13. });
  14. export const name = deployment.metadata.name;
复制代码
4.3.5、部署Stack

  1. # Set K8s Config
  2. pulumi config set kubernetes:context arn:aws-cn:eks:cn-northwest-1:xxx:cluster/eks-cluster-pulumi
  3. # 部署 stack, Pulumi 确定创建堆栈所需的资源。首先,显示将要进行的更改的预览
  4. pulumi up
  5. Previewing update (dev):
  6.      Type                           Name            Plan
  7. +   pulumi:pulumi:Stack            quickstart-dev  create
  8. +   └─ kubernetes:apps:Deployment  nginx           create
  9. Resources:
  10.     + 2 to create
  11. Do you want to perform this update? yes
  12. Updating (dev):
  13.      Type                           Name            Status
  14. +   pulumi:pulumi:Stack            quickstart-dev  created
  15. +   └─ kubernetes:apps:Deployment  nginx           created
  16. Outputs:
  17.     name: "nginx-xw231xdt"
  18. Resources:
  19.     + 2 created
  20. Duration: 11s
复制代码


4.3.6、销毁Stack


  1. pulumi destroy
  2. # 系统将提示你确保确实要删除这些资源。
  3. Previewing destroy (dev):
  4.      Type                           Name            Plan
  5. -   pulumi:pulumi:Stack            quickstart-dev  delete
  6. -   ├─ kubernetes:core:Service     nginx           delete
  7. -   └─ kubernetes:apps:Deployment  nginx           delete
  8. Outputs:
  9.   - ip: "10.105.234.140"
  10. Resources:
  11.     - 3 to delete
  12. Do you want to perform this destroy? yes
  13. Destroying (dev):
  14.      Type                           Name            Status
  15. -   pulumi:pulumi:Stack            quickstart-dev  deleted
  16. -   ├─ kubernetes:core:Service     nginx           deleted
  17. -   └─ kubernetes:apps:Deployment  nginx           deleted
  18. Outputs:
  19.   - ip: "10.105.234.140"
  20. Resources:
  21.     - 3 deleted
  22. Duration: 1s
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4