在容器中或不在容器中部署具有微服务架构的Go应用?

I'm new to DevOps specifically using golang and microservice architecture.

I'm wondering if go applications should or should not be deployed in containers (Docker). In this case, I have a system built with micro-service architecture. For example here, I have 2 web services, A and B. Also I have another web server acts as a gateway in front of those two.

Both A and B need access for a database, MySQL for example. A handles table A, and B handles table B.

I know that in Go, source codes are compiled into a single executable binary file. And because I have 3 services here, I have 3 binaries. All three run as web server exposing JSON REST API.

My questions are these:

  • Can I deploy these servers together in one host running on different ports? If my host get an IP x.x.x.x for example, my gateway can run in x.x.x.x:80, A in port 81, and B in port 82 for example. A and B will talk to a MySQL server somewhere outside or maybe inside the same host. Is this a good practice? Can Continuous Deployment works with this practice?

  • Why should I deploy and run those binaries inside containers like Docker? I know that since its release few years ago, Docker had found its way to be integrated inside a development workflow easily. But of course using Docker is not as simple as just compiling the code into a binary and then moving it to a deployment server. Using Docker we have to put the executable inside the container and then move the container as well to the deployment server.

  • What about scalibility and high availability without using Docker? Can I just replicate my services and run them all at once in different hosts using a load balancer? This way I should deploy A, B, and gateway in one host, and another A, B, and gateway in another host, then setup load balancer in front of them. A, B, and the gateway runs in port 80, 81, and 82 respectively. This way I could have thousands of nodes in a form of VMs or LXD containers maybe, spread accross hundreds of bare metals, deployed with a simple bash script and ssh, or Ansible if things get complex. Yes or no?

  • And what about the scalability and availability of using Docker? Should I just put all my services inside containers and manage them with something like Kubernetes to achieve high availability? Doing this does add overhead, right? Because the team will have to learn new technology like Kubernetes if they haven't known it yet.

  • Can you give me an example of some best practices of deploying golang services?

drrog9853
drrog9853 正是我在想什么。抱歉,我是Stackoverflow的新手,但是下次我将尝试提出更具体的问题。顺便说一句,Reddit在我的位置被阻止了,所以代理访问缓慢且不方便,因此我很难访问它。
2 年多之前 回复
dongnai8013
dongnai8013 没有使用容器的真正理由。在大多数情况下,容器可以解决Go应用程序所没有的问题,因为Go二进制文件已经是自包含的。就是说...这个问题太笼统了,很大程度上是基于观点的。尝试Reddit。
2 年多之前 回复
doulizhi1247
doulizhi1247 我看到了10多个问题,这个问题太广泛了,无法解决一个SO问题。
2 年多之前 回复

2个回答

I'm wondering if go applications should or should not be deployed in containers (Docker)
Why should I deploy and run those binaries inside containers like Docker?

Of course, provided you separate the build from the actual final image (in order to not include in said final image build dependencies)
See "Golang, Docker and multistage build" from Matteo Madeddu.

Can I deploy these servers together in one host running on different ports?

Actually, they could all run in their own container on their own port, even if that port is the same.
Intra-container communication will work, using EXPOSEd port. However, if they are accessed from outside, then their published port need to be different indeed.

What about scalibility and high availability without using Docker?
And what about the scalability and availability of using Docker?

As soon as you are talking about dynamic status, some kind of orchestration will be involved: see Docker Swarm or Kubernetes for efficient cluster management.
Both are available with the latest docker.

Examples:



VonC的答案很棒。 我只想补充一件事:Golang非常适合容器,因为它内置了对自持二进制文件的支持。 这意味着您可以构建只有几MB大小的容器,而不是带有阿尔卑斯等的典型容器(通常是数百MB)。</ p>

请查看此阅读。 </ p>
</ div>

展开原文

原文

VonCs answer is great. I'd just like to add one thing: Golang is perfect for containers because it has built in support for self-sustained binaries. And that means you can build containers that are just the size of a few MB instead of the typical containers with alpine etc. that are often hundreds of MB.

Check out this read.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐