欧美三级电影完整|亚洲一二三四久久|性爱视频精品一区二区免费在线观看|国产精品啪啪视频|婷婷六月综合操人妻视频网站|99爱免费视频在线观看|美女一级片在线观看|北京熟女88av|免费看黄色A级电影|欧美黄色毛片儿

Docker-compose 到 Kubernetes 的遷移工具!

2023-04-12

在 skippbox,我們開發(fā)了 Kompose 這一工具,他能夠自動把 Docker Compose 應用轉(zhuǎn)換為 Kubernetes 描述文件。利用一個簡單的 kompose up命令,就可以在 Kubernetes 集群上啟動 Compose 應用。我們非常樂于將其捐獻給 Kubernetes Incubator。下面介紹一下這一工具的開發(fā)動機和用法。


Docker 給了開發(fā)者以巨大的幫助。讓每個人都能夠從 Docker Registry 啟動一個打包好的 Docker 應用。為了對付多容器應用, Docker 開發(fā)了 Docker-compose (也就是 Compose)。Compose 借助 yaml 格式的描述文件來定義一個多容器應用,然后就可以用一個簡單的 docker-compose up來啟動這一應用中的多個容器。然而,Compose 只能夠在本地或者 Docker Swarm 集群中運行。


那如果我們需要在 Swarm 之外運行怎么辦?比如 Kubernetes?Compose 格式并非為分布式而誕生的。所以,你只能為你選擇的容器編排工具重新編寫應用描述文件。


我們利用 Kompose,能夠簡單的完成將應用從 Docker Swarm 到 Kubernetes 的轉(zhuǎn)換過程,這樣就為 Docker 用戶敞開了 Kubernetes 的大門。


今年夏天,來自紅帽的 Tomas Kral 和 Suraj Deshmukh,以及來自 Google 的 Janet Kuo,他們和 Kompose 的主要開發(fā)者 Nguyen An-Tu 一起為 Kompose 錦上添花。我們把 Kompose 提交給 Kubernets Incubator,得到了 Kubernetes 社區(qū)的支持,現(xiàn)在可以在 Kubernetes Incubator 找到 Kompose。


Kompose 目前支持 Docker-compose v2 格式,最近還加入了持久卷所有權(quán)(PVC)、以及多容器 Pod 的支持。除了缺省的 Kubernetes 之外,我們還支持 Openshift 的發(fā)布能力。Kompose 現(xiàn)在還出現(xiàn)在了 Fedora 包中,未來也會進入CentOS中去。Kompose 是一個 Golang 應用,可以從 Github 上獲取。下面讓我們跳過 Build 環(huán)節(jié)直接進入實例。


Docker 的留言板應用


留言板應用是 Kubernetes 的權(quán)威示例。如果要用 Docker Compose 來實現(xiàn)留言板,可以用下面的代碼:


version: "2"

services:
redis-master:
image: gcr.io/google_containers/redis:e2e
ports:
- "6379"
redis-slave:
image: gcr.io/google_samples/gb-redisslave:v1
ports:
- "6379"
environment:
- GET_HOSTS_FROM=dns
frontend:
image: gcr.io/google-samples/gb-frontend:v4
ports:
- "80:80"
environment:
- GET_HOSTS_FROM=dns

其中包含了三個服務:


一個 Redis 主節(jié)點;
一組能夠橫向擴展并借助 DNS 找到 Master 的 Redis 從節(jié)點;
暴露于 80 端口的 PHP 前端。
這些組合在一起,讓用戶可以發(fā)表留言,并保存在 Redis 集群中。


要啟動這個應用:


$ docker-compose -f docker-guestbook.yml up -d
Creating network "examples_default" with the default driver
Creating examples_redis-slave_1
Creating examples_frontend_1
Creating examples_redis-master_1

這就是一個簡單的 Docker 用法,下面我肯看看如何在不重寫任何東西的情況下,讓這些工作在 Kubernetes 上完成。


Kompose 的留言板應用


Kompose 目前有三個主要的命令:up、down 以及 convert。為了行文方便,我們只簡單說一下留言吧應用的啟動。


跟 docker-compose 類似,我們可以用 kompose up 命令處理 Docker compose 文件,來啟動應用:


$ kompose -f ./examples/docker-guestbook.yml up
We are going to create Kubernetes deployment and service for your dockerized application.
If you need more kind of controllers, use 'kompose convert' and 'kubectl create -f' instead.

INFO[0000] Successfully created service: redis-master
INFO[0000] Successfully created service: redis-slave
INFO[0000] Successfully created service: frontend
INFO[0000] Successfully created deployment: redis-master
INFO[0000] Successfully created deployment: redis-slave
INFO[0000] Successfully created deployment: frontend

Application has been deployed to Kubernetes. You can run 'kubectl get deployment,svc' for details.

Kompose 自動把 Docker-compose 文件轉(zhuǎn)為 Kuberntes 對象。缺省情況下,他會為一個 Compose 服務創(chuàng)建一個 Deployment 以及一個服務。另外還能自動檢測當前的 Kuberntes 端點,并在上面創(chuàng)建對象??梢酝ㄟ^一系列的選項來創(chuàng)建 Replication Controller、Replica Set 或者 Daemon Set。


就這樣完成了自動轉(zhuǎn)換,如果你了解一些 Kubernetes 的話,可以用 kubectl 命令來看看集群上運行的留言板。


$ kubectl get pods,svc,deployments
NAME READY STATUS RESTARTS AGE
frontend-3780173733-0ayyx 1/1 Running 0 1m
redis-master-3028862641-8miqn 1/1 Running 0 1m
redis-slave-3788432149-t3ejp 1/1 Running 0 1m
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
frontend 10.0.0.34 80/TCP 1m
redis-master 10.0.0.219 6379/TCP 1m
redis-slave 10.0.0.84 6379/TCP 1m
NAME DESIRED CURRENT UP-TO-DATE

AVAILABLE AGE
frontend 1 1 1 1 1m
redis-master 1 1 1 1 1m
redis-slave 1 1 1 1 1m

看到了三個服務、三個 Deployment 以及三個 Pod??梢酝ㄟ^ frontend 服務來訪問留言板應用。只不過這次的留言板,是從 Docker-Compose 文件啟動的。



以上給讀者快速的介紹了一下 kompose。還有很多激動人心的特性,例如創(chuàng)建不同類型的資源、創(chuàng)建 Helm Chars,甚至可以使用試驗性的 Docker bundle 格式進行輸入(Lachlan Evenson 的博客:using a Docker bundle with Kubernetes)??梢栽谖覀兊?KubeCon 上的視頻 中看到完整的演示。


前往 Kubernetes incubator 獲取 Kompose,可以幫助你輕松地把應用從 Docker Compose 遷移為 Kubernetes 集群應用。


轉(zhuǎn)自:https://www.linuxprobe.com/docker-compose-kubernetes.html


本文僅代表作者觀點,版權(quán)歸原創(chuàng)者所有,如需轉(zhuǎn)載請在文中注明來源及作者名字。

免責聲明:本文系轉(zhuǎn)載編輯文章,僅作分享之用。如分享內(nèi)容、圖片侵犯到您的版權(quán)或非授權(quán)發(fā)布,請及時與我們聯(lián)系進行審核處理或刪除,您可以發(fā)送材料至郵箱:service@tojoy.com