前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >结合使用 Draft 与 Tencent Kubernetes Engine (TKE)

结合使用 Draft 与 Tencent Kubernetes Engine (TKE)

原创
作者头像
张善友
发布2019-04-01 12:37:04
11K1
发布2019-04-01 12:37:04
举报
文章被收录于专栏:张善友的专栏张善友的专栏

Draft 是一种开源工具,有助于在 Kubernetes 群集中打包和部署应用程序容器,让你专注于开发周期 - 专注开发的“内部循环”。 在开发代码期间,但尚未将代码提交到版本控制之前,Draft 将会运行。 借助 Draft,可在代码发生更改时快速将应用程序重新部署到 Kubernetes。本文介绍如何对 TKE上的 Kubernetes 群集使用 Draft。

必备组件

本文中所有的步骤假设已创建 TKE群集并已与该群集建立 kubectl 连接。 如果你还没有,请参阅 TKE快速入门https://cloud.tencent.com/product/tke/getting-started

Tencent Hub容器注册表 (tencenthub) 中需有一个专用 Docker 注册表。 有关创建 tencenthub实例的步骤,请参阅 TencentHub容器注册表快速入门https://cloud.tencent.com/document/product/857/17143

Helm 也必须安装在 TKE群集中。 TKE的新版本还在内测中,需求申请内测开通 https://cloud.tencent.com/document/product/457/31699

最后,必须安装 Docker: https://www.docker.com/

安装 Draft

Draft CLI 是一个在开发环境上运行的客户端,可将代码部署到 Kubernetes 群集中。 请参阅 Draft 安装指南:https://github.com/Azure/draft/tree/master/docs 。本文我们使用windows环境。

https://github.com/Azure/draft/releases 下载最新的0.16版本,我把它解压放在目录C:\workshop\draft,把这个目录路径加入到环境变量Path 即完成客户端的安装。

使用 draft init 命令初始化 Draft。

接下来也需要安装draft 依赖的Helm ,Helm的安装参考 https://helm.sh/docs/using_helm/#installing-helm,我直接从https://github.com/helm/helm/releases 下载,我也把它解压在C:\workshop\draft。

c:\workshop\draft>helm init

Creating C:\Users\geffzhang\.helm\repository\repositories.yaml

Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com

Error: Looks like "https://kubernetes-charts.storage.googleapis.com" is not a valid chart repository or cannot be reached: Get https://kubernetes-charts.storage.googleapis.com/index.yaml: read tcp 192.168.5.238:50765->172.217.160.80:443: wsarecv: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

helm init会连接kubectl默认连接的kubernetes集群(可以通过kubectl config view查看),一旦连接集群成功,tiller会被安装到kube-system namespace中。

但是,在国内环境中,我们直接使用helm init会无法拉取到tiller镜像,需要手动指定镜像地址,同时如果Kubernetes集群开启了rbac,还需要指定运行tiller的servicaccount,并为该serviceaccount作合适的授权。

https://github.com/Azure/draft/releases 下载最新的0.16版本,我把它解压放在目录C:\workshop\draft,把这个目录路径加入到环境变量Path 即完成客户端的安装。

使用 draft init 命令初始化 Draft。

接下来也需要安装draft 依赖的Helm ,Helm的安装参考 https://helm.sh/docs/using_helm/#installing-helm,我直接从https://github.com/helm/helm/releases 下载,我也把它解压在C:\workshop\draft。

c:\workshop\draft>helm init

Creating C:\Users\geffzhang\.helm\repository\repositories.yaml

Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com

Error: Looks like "https://kubernetes-charts.storage.googleapis.com" is not a valid chart repository or cannot be reached: Get https://kubernetes-charts.storage.googleapis.com/index.yaml: read tcp 192.168.5.238:50765->172.217.160.80:443: wsarecv: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

helm init会连接kubectl默认连接的kubernetes集群(可以通过kubectl config view查看),一旦连接集群成功,tiller会被安装到kube-system namespace中。

但是,在国内环境中,我们直接使用helm init会无法拉取到tiller镜像,需要手动指定镜像地址,同时如果Kubernetes集群开启了rbac,还需要指定运行tiller的servicaccount,并为该serviceaccount作合适的授权。

最简单方法是手动访问https://kubernetes-charts.storage.googleapis.com/index.yaml, 下载保存到C:\Users\geffzhang\.helm\repository\repositories.yaml

配置 Draft

Draft 在本地生成容器映像,然后从本地注册表部署这些映像(例如使用 Minikube),或使用指定的映像注册表。 本文使用 Tencent Hub容器注册表 (Tecenthub),因此,必须在 TKE群集与 TencentHub注册表之间建立信任关系,然后将 Draft 配置为向 TencentHub推送容器映像。

c:\workshop\Github\draft\examples\example-dotnet>docker login --username=geffzhang_weyhd_com hub.tencentyun.com

Password:

Login Succeeded

c:\workshop\Github\draft\examples\example-dotnet>draft up

Draft Up Started: 'example-dotnet': 01D7BCHQ4HK1P67582WWFZ92W6

example-dotnet: Building Docker Image: SUCCESS ⚓ (0.9996s)

example-dotnet: Pushing Docker Image: SUCCESS ⚓ (2.5611s)

example-dotnet: Releasing Application: SUCCESS ⚓ (3.5553s)

Inspect the logs with `draft logs 01D7BCHQ4HK1P67582WWFZ92W6`

在本地测试应用程序

若要测试应用程序,请使用 draft connect 命令。 此命令将代理与 Kubernetes pod 之间的安全连接。 完成后,可在提供的 URL 上访问应用程序。

c:\workshop\Github\draft\examples\example-dotnet>draft connect

Connect to example-dotnet:80 on localhost:52672

[example-dotnet]: Hosting environment: Production

[example-dotnet]: Content root path: /app

[example-dotnet]: Now listening on: http://[::]:80

[example-dotnet]: Application started. Press Ctrl+C to shut down.

[example-dotnet]: [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]

[example-dotnet]: Request starting HTTP/1.1 GET http://localhost:52672/

[example-dotnet]: [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]

[example-dotnet]: Request finished in 67.1166ms 200

[example-dotnet]: [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]

[example-dotnet]: Request starting HTTP/1.1 GET http://localhost:52672/favicon.ico

[example-dotnet]: [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]

[example-dotnet]: Request finished in 0.1648ms 200

循环访问应用程序

已配置 Draft 并且应用程序正在 Kubernetes 中运行,现在应开始迭代代码。 每当要测试更新的代码时,请运行 draft up 命令来更新正在运行的应用程序。

c:\workshop\Github\draft\examples\example-dotnet>draft up

Draft Up Started: 'example-dotnet': 01D7BCR2AHENBZHGYMPHMKQ9VD

example-dotnet: Building Docker Image: SUCCESS ⚓ (26.0217s)

example-dotnet: Pushing Docker Image: SUCCESS ⚓ (293.0051s)

example-dotnet: Releasing Application: SUCCESS ⚓ (4.1565s)

Inspect the logs with `draft logs 01D7BCR2AHENBZHGYMPHMKQ9VD`

c:\workshop\Github\draft\examples\example-dotnet>draft connect

Connect to example-dotnet:80 on localhost:52980

[example-dotnet]: Hosting environment: Production

[example-dotnet]: Content root path: /app

[example-dotnet]: Now listening on: http://[::]:80

[example-dotnet]: Application started. Press Ctrl+C to shut down.

[example-dotnet]: [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]

[example-dotnet]: Request starting HTTP/1.1 GET http://localhost:52980/

[example-dotnet]: [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]

[example-dotnet]: Request finished in 63.1118ms 200

[example-dotnet]: [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]

[example-dotnet]: Request starting HTTP/1.1 GET http://localhost:52980/favicon.ico

[example-dotnet]: [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]

[example-dotnet]: Request finished in 0.1467ms 200

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 必备组件
  • 安装 Draft
  • 配置 Draft
  • 在本地测试应用程序
  • 循环访问应用程序
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档