1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

docker-compose.yml を kompose convert して Azure Kubernetes Service (AKS) で動かしました

Last updated at Posted at 2021-07-28

概要

この記事 にある docker-compose.yml を kcompose convert することにより、Kuberbetesのマニフェストを作成し、それを元にAKSでコンテナを問題なく稼働できることを確認します。

ローカル環境

macOS Big Sur 11.3
python 3.8.3

事前準備

この記事 を参考にして、AKS と ACR を構築し、AKSクラスター上で動く Node の確認まで完了していること。


マニフェストの作成

Kompose のインストール

$ curl -L https://github.com/kubernetes/kompose/releases/download/v1.22.0/kompose-darwin-amd64 -o kompose
$ chmod +x kompose
$ sudo mv ./kompose /usr/local/bin/kompose      

docker-compose.yml のコンバート

以下の docker-compose.yml を対象とします。

version: "2"

services:

  redis-master:
    image: k8s.gcr.io/redis:e2e
    ports:
      - "6379"

  redis-slave:
    image: gcr.io/google_samples/gb-redisslave:v3
    ports:
      - "6379"
    environment:
      - GET_HOSTS_FROM=dns

  frontend:
    image: gcr.io/google-samples/gb-frontend:v4
    ports:
      - "80:80"
    environment:
      - GET_HOSTS_FROM=dns
    labels:
      kompose.service.type: LoadBalancer

kubernetes へのコンバートの実行

$ kompose convert -f docker-compose.yml   

IINFO Kubernetes file "frontend-service.yaml" created 
INFO Kubernetes file "redis-master-service.yaml" created 
INFO Kubernetes file "redis-slave-service.yaml" created 
INFO Kubernetes file "frontend-deployment.yaml" created 
INFO Kubernetes file "redis-master-deployment.yaml" created 
INFO Kubernetes file "redis-slave-deployment.yaml" created 

AKS 上でのPodの起動

クラスター上で動く Node の確認

$ kubectl get node

Podの作成

$ kubectl apply -f frontend-service.yaml,redis-master-service.yaml,redis-slave-service.yaml,frontend-deployment.yaml,redis-master-deployment.yaml,redis-slave-deployment.yaml

service/frontend created
service/redis-master created
service/redis-slave created
deployment.apps/frontend created
deployment.apps/redis-master created
deployment.apps/redis-slave created

Podの確認

$ kubectl get pods

NAME                           READY   STATUS    RESTARTS   AGE
frontend-6bd559fc9d-8r75p      1/1     Running   0          47s
redis-master-77b6f7887-bmjg7   1/1     Running   0          47s
redis-slave-7d89659bdc-nd7kj   1/1     Running   0          47s

アプリケーションの確認

サービスの確認

$ kubectl describe svc frontend

Name:                     frontend
Namespace:                default
Labels:                   io.kompose.service=frontend
Annotations:              kompose.cmd: kompose convert -f docker-compose.yml
                          kompose.service.type: LoadBalancer
                          kompose.version: 1.22.0 (955b78124)
Selector:                 io.kompose.service=frontend
Type:                     LoadBalancer
IP Families:              <none>
IP:                       10.0.7.99
IPs:                      <none>
LoadBalancer Ingress:     20.89.87.139
Port:                     80  80/TCP
TargetPort:               80/TCP
NodePort:                 80  31064/TCP
Endpoints:                10.244.0.7:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason                Age   From                Message
  ----    ------                ----  ----                -------
  Normal  EnsuringLoadBalancer  110s  service-controller  Ensuring load balancer
  Normal  EnsuredLoadBalancer   105s  service-controller  Ensured load balancer

アプリケーションへのアクセス

$ curl http://20.89.87.139

<html ng-app="redis">
  <head>
    <title>Guestbook</title>
        :
  </head>
  <body ng-controller="RedisCtrl">
        :
  </body>
</html>

Podの削除

$ kubectl delete -f frontend-service.yaml,redis-master-service.yaml,redis-slave-service.yaml,frontend-deployment.yaml,redis-master-deployment.yaml,redis-slave-deployment.yaml

最後に

docker-compose.yml を kompose convert することにより deployment と Service のマニフェストが作成され、それらを AKS に kubectl apply することにより問題なくアプリケーションが稼働することを確認しました。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?