借助AWS Copilot,让Kubernetes有了第二个想法-数据生活

谁在乎? (Who Cares?)

Kubernetes is a fantastic container orchestration tool for scalable cloud computing applications. After years of development and use internally, Google open-sourced the tool in 2014, leading to an explosion of adoption from small businesses and enterprises alike. That being said, we don’t always need all of its batteries included. Although it provides a relatively convenient declarative interface via YAML configuration files, a solo developer or small team still has numerous details to worry about for deployment, such as the following:

Kubernetes是用于可伸缩云计算应用程序的出色容器编排工具。 经过多年的内部开发和使用,Google于2014年对该工具进行了开源,导致小型企业和企业的采用量激增。 话虽如此,我们并不总是需要包括所有的电池。 尽管它通过YAML配置文件提供了一个相对方便的声明性界面,但是一个单独的开发人员或小型团队仍然需要考虑很多细节来进行部署,例如:

  • Virtual private cloud (VPC)

    虚拟私有云(VPC)
  • SSL certificate

    SSL证书
  • Load balancer

    负载均衡器
  • Container registry

    容器注册表

All of these details are crucial for managing a cloud solution, and some focus on this area as their main job. However, others want to focus on the application itself.

所有这些细节对于管理云解决方案都是至关重要的,有些细节则将这一领域作为主要工作。 但是,其他人则希望专注于应用程序本身。

In many small projects, you don’t have a complex 80-bajillion-container behemoth requiring Kubernetes for orchestration. I don’t have stats for this, but I bet most proof-of-concept projects consist of 1–4 containers (Aside: sounds like a fun project to parse Github/Docker Hub to find out). For these projects, having a rather straight-forward way to tell your cloud provider “hey, here’s a container image. Put this up in the sky and charge me for what it consumes” would suffice.

在许多小型项目中,您不会遇到需要使用Kubernetes进行编排的复杂80兆容器的庞然大物。 我没有统计数据,但是我敢打赌,大多数概念验证项目都由1-4个容器组成(此外:听起来像是一个有趣的项目,可以解析Github / Docker Hub找出答案)。 对于这些项目,可以采用一种非常简单的方法来告诉您的云提供商“嘿,这是一个容器映像。 将其放在天空中并向我收取所消耗的东西就足够了。

Enter ECS, with its convenient new CLI copilot.

借助便捷的新CLI copilot进入ECS。

从应用程序到部署,快速 (From App to Deploy, Fast)

I put together a demo application to drive this process and allow you to quickly see it in action. For the doers, you can find the link in the Resources section below. Let’s take an off-the-shelf sentiment analyzer from the NLTK library, and serve sentiment scores for text inputs using my new favorite python API library: FastAPI. There is absolutely no need for me to give an overview of FastAPI, because one of the following fits your case:

我整理了一个演示应用程序来驱动此过程,并允许您快速查看实际操作。 对于行动者,您可以在下面的参考资料部分中找到链接。 让我们从NLTK库中获取一个现成的情绪分析器,并使用我最喜欢的新python API库:FastAPI为文本输入提供情绪分数。 绝对不需要我概述FastAPI,因为以下情况之一适合您的情况:

  1. You already know and love it

    您已经知道并喜欢它
  2. You are about to, via its great documentation

    您即将通过其出色的文档

Remembering, application developers mainly care about 1) the application code and 2) the container it sits in. Well, here they are.

记住,应用程序开发人员主要关心1)应用程序代码和2)它所在的容器。

from fastapi import FastAPI


from fastapi_sentiment import sentiment_analysis
from fastapi_sentiment.models import (
    SentimentDocument,
    SentimentScoring,
    Message
)


app = FastAPI()




@app.get("/", response_model=Message, status_code=200)
def read_root() -> Message:
    return {
        'message': 'Hello World'
    }




@app.get("/health", response_model=Message, status_code=200)
async def get_health() -> Message:
    return {
        'message': 'Still kicking'
    }




@app.post("/sentiment", response_model=SentimentScoring, status_code=200)
async def get_sentiment(document: SentimentDocument) -> SentimentScoring:
    return sentiment_analysis.get_sentiment(document.text)
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7


# System-related
WORKDIR /app
COPY . .


# Install package
RUN pip3 install --upgrade pip && \
    python3 setup.py install


# NLTK downloads
RUN python3 -c "import nltk; nltk.download('vader_lexicon')"


# Networking
EXPOSE 80


ENV APP_MODULE='fastapi_sentiment.main:app'

There’s a Makefile with some convenience goodies as well, but I won't throw that in your face. Check it out here if you're curious.

还有一个带有一些便利功能的Makefile ,但是我不会把它丢在您的脸上。 如果您好奇的话,请在这里查看。

Now that we have our app, the deploy sequence is as simple as something like below.

现在我们有了我们的应用程序,部署过程就像下面这样简单。

make build test
copilot init
copilot env init \
--name prod \
--profile default \
--app fastapi-sentiment
copilot svc deploy \
--name fastapi-sentiment \
--env prod

For those curious about seeing inside of the flow of the copilot commands above, check out the show below, taken from Efe Karakus's article on the AWS blog.

对于那些好奇地看到上面的copilot命令流程内部的人,请查看以下显示,该显示取自AWS博客上Efe Karakus的文章。

Image for post
source] ]

You may be wondering how this compares to the canonical `kube apply -f deployment.yml`, thinking that it’s more commands to achieve the same thing. Remember that the commands above will set up both your infrastructure and application. Therefore, the equivalent comparison for a Kubernetes application would be to combine all of the infrastructure-as-code (IaC) setup with the Kubernetes config files. That…is much more work.

您可能想知道这与规范的`kube apply -f deployment.yml`相比如何,以为实现同一件事需要更多的命令。 请记住,以上命令将同时设置您的基础结构和应用程序。 因此,Kubernetes应用程序的等效比较是将所有基础结构代码(IaC)设置与Kubernetes配置文件结合在一起。 那……还有更多工作。

我们活着 (We’re Live)

Image for post
Photo by Wil Stewart on Unsplash
Wil StewartUnsplash拍摄的照片

With those few commands, our application is now publicly available (if you so choose) for prime time. Not bad for a few lines of good. All of this time saved can now be used for more prototyping, testing, or playing with your cat.

使用这几个命令,我们的应用程序现在可以在黄金时间公开使用(如果您愿意的话)。 好几行还不错。 现在,所有节省下来的时间都可以用于更多的原型制作,测试或与猫一起玩。

Image for post
Some simple commands demonstrating access to the deployed API
一些简单的命令演示对已部署API的访问

This demo only scratches the surface of what ECS and copilot can and will do. There are resources for pipelines, planned integrations with docker-compose, and simple options for CI/CD integration. For more reading, check out the resources below.

此演示仅刮擦ECS和copilot可以而且将做的事情的表面。 有管道资源,与docker-compose计划集成以及CI / CD集成的简单选项的资源。 有关更多阅读,请查看下面的资源。

Help me help you: tell me what to do next.

帮我帮您: 告诉我下一步该怎么做

资源资源 (Resources)

保持最新 (Stay Up To Date)

That’s all for this one. However, things happen quickly in academics and industry! Keep yourself updated with the LifeWithData blog, articles on Medium, and my Twitter.

这就是全部。 但是,事情在学术界和行业中Swift发生! 通过LifeWithData博客, Medium上的文章以及我的Twitter 随时了解最新信息。

Image for post

Originally published at https://www.lifewithdata.org on August 22, 2020.

最初于 2020年8月22日 https://www.lifewithdata.org 发布

翻译自: https://towardsdatascience.com/with-an-aws-copilot-give-kubernetes-a-second-thought-life-with-data-95d11761c27e

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值