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

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

原文地址:https://cloud.tencent.com/developer/article/1409013

.NET社区新闻,深度好文,欢迎访问公众号文章汇总 http://www.csharpkit.com
640?wx_fmt=jpeg

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/316463.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[ZJOI2010] 贪吃的老鼠(二分+差分+神仙建图网络流)

problem luogu-P2570 solution 卧槽网络流尼玛神题 首先这个最小延长时间 TTT ,套路地考虑二分,将问题转化为判定性问题。 其次 n,mn,mn,m 和奶酪存在时间 [l,r][l,r][l,r] 的量级差很大,我们肯定会猜想一段时间内选择吃奶酪的老鼠是一样…

cf1553D. Backspace

cf1553D. Backspace 题意: 有一个字符串A,现在将其一个一个输入至B中,在输入一个字符时,如果按下backspace,那么这个字符不会被键入,而且如果B不为空,则前一位(B.back)也会被删除,现给出一个字符串C,问能否得到一个B,使得BC 题解: 为了通…

基于IdentityServer的系统对接微信公众号

业务需求公司有两个业务系统,A和B,AB用户之间属于多对一的关系,数据库里面也就是两张表,A表有个外键指向B。现在需要实现以下几个功能。A用户扫描B的二维码,填写相关的注册信息,注册完成之后自动属于B。也就…

[TJOI2012] 旅游(树的直径)

problem 写的什么jb题意!这个语文水平。。。。 洛谷的一堆题解看下来也没懂他们懂得题目大意,真是给我蚌埠住了 luogu评测链接 一句话题意:给定一个三角剖分,求任意两顶点穿过的最多三角形个数(只经过某三角形顶点…

Python知识(4/20):Python条件判断

任何一个复杂的系统都是由三种基本结构组成:顺序结构、分支结构、循环结构。其中 顺序结构最简单,程序从上到下依次执行,就如同生活中一条笔直的大马路,一路畅行无阻; 分支结构是指当程序执行到某步时,需根…

Ocelot Api网关教程(9)- QoS

本文介绍Ocelot中的QoS(Quality of Service),其使用了Polly对超时等请求下游失败等情况进行熔断。1、添加Nuget包添加 Ocelot.Provider.Polly 到OcelotGetway项目中2、修改 Startup.ConfigureServices 如下来添加Polly:services .AddOcelot(new Confi…

cf1553F. Pairwise Modulo

cf1553F. Pairwise Modulo 题意: 给你一个数组a,a由n个不同的数组成,让你求出对应的数组p 数组p的定义为: pk∑1≤i,j≤kaimodajp_{k}\sum_{1\leq i,j\leq k}a_{i} \mod a_{j}pk​∑1≤i,j≤k​ai​modaj​ 题解: 官方题解 首…

[ZJOI2011]营救皮卡丘(费用流 + 最短路)

problem luogu-P4542 solution 刚开始就直观感觉 dpdpdp 不动,却有个看似“理所当然”的贪心:每次跑 kkk 个人所在点到扩展据点的最短距离,然后让最近的人去破环那个据点。 啪啪敲完后小样例(实在太水)就过了&…

Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)

Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 Div. 2) 题号题目知识点AGame of LifeBLord of the ValuesCCompression and ExpansionDLove-HateECrypto LightsFFavorite GameGTry BookingHHopping Around the Array

Abp框架准备加入.NET Foundation

Abp团队正准备尝试将Abp项目加入.NET Foundation!既然申请了,必然有很大的自信能够成功,请大家等待好消息!Abp中文网会第一时间跟进.点击阅读原文查看最新进展.

[ZJOI2011] 道馆之战(树链剖分)

problem luogu-P4679 理解清楚题意又是一个世纪的更迭了 给定一个树,每个节点位置上实际放了两个节点。 然后若干次修改和查询。... 能走,#\## 不能走。 询问 u→vu\rightarrow vu→v 的简单路径上最长能走的距离。(是强制从 uuu 开始&a…

[NOI2008] 志愿者招募(线性规划-对偶问题-费用流)

problem luogu-P3980 solution 志愿者连续工作 [si,ti][s_i,t_i][si​,ti​] 天,我们可以提炼出网络流二十四题中《最长k可重区间集问题》的模型。 同样地,把 1∼n1\sim n1∼n 天抽象成一条 1∼n11\sim n11∼n1 个点的链条。 源点 s→1s\rightarrow…

互达的集合(线段树)

problem 给定数组 l,rl,rl,r。求有多少个非空集合 SSS,满足 ∀i,j∈Sli≤j≤ri\forall_{i,j\in S}\ l_i\le j\le r_i∀i,j∈S​ li​≤j≤ri​。 集合内对于任意一个点而言,其余点均能被自己的范围覆盖到。 n≤2e5n\le 2e5n≤2e5。 solution 分享一下…

【学习笔记】线性规划与对偶问题和LP对偶费用流([ZJOI2013]防守战线题解)

线性规划与对偶问题 原问题: min⁡{7x1x25x3}s.t.{x1−x23x3≥105x12x2−x3≥6xi≥0\min\{7x_1x_25x_3\} \\ s.t.\begin{cases} x_1-x_23x_3\ge 10\\ 5x_12x_2-x_3\ge 6\\ x_i\ge 0\end{cases} min{7x1​x2​5x3​}s.t.⎩⎪⎨⎪⎧​x1​−x2​3x3​≥105x1​2x2​−…

【学习笔记】DAG / 一般有向图的支配树 / 灭绝树

定义与声明 一个有向图 GGG。给定一个起点 sss,假设 sss 能到达所有点。 若去掉某个点 iii 后,sss 无法到达 jjj,则称 iii 为 jjj 的支配点。 显然支配点存在传递关系。 以 sss 为根,使得对于任意节点 iii,其树上祖…

[ZJOI2014] 星系调查(树上差分 + 数学推式子)

problem luogu-P3340 题面写得那么长,其实说白了就是求一条直线,使得若干个点到这条直线的距离平方的和最小,求这个最小值。 solution 我超爱数学,数学就是我的命,我一天不学数学我就难受! 假设拟合出…

[ZJOI2014] 璀璨光华(bfs建图 + dfs搜索)

problem luogu-P3342 solution 你感觉这道题没考什么,又感觉考了什么 通过样例以及题面,我们并未获取到『立方体每个小方块的编号是按一定规则命名』的信息。 也就是说,我们需要通过输入的每个小方块相邻的编号的信息来建出这个立方体的…

cf1523A. Game of Life

cf1523A. Game of Life 题意: 包含n个元素的数组,数值为1或0,如果一个元素为0,并且其周围正好只有一个为1的元素,那么下一刻本元素也会变成1. 给你一个数值,问你m次时刻后数组的状态 题解: …

SignalR 中丰富多彩的消息推送方式

在上一篇 SignalR 文章中,演示了如何通过 SignalR 实现了简单的聊天室功能;本着简洁就是美的原则,这一篇我们也来聊聊在 SignalR 中的用户和组的概念,理解这些基础知识有助于更好的开发基于 SignalR 的应用,通过对用户…

Visual Studio 2019 使用 Live Share

一.前言Visual Studio 2019 在今天发布(北京时间)了,这次带来了一个比较有趣的 Live Share 功能,使用它可以进行更好的协作开发。主要功能:更多资料可看官方介绍:Visual Studio 实时共享什么是Visual Studi…