Kubernetesで各種DBを作成する

 

(8.0.23)
https://qiita.com/kazuki43zoo/items/7d6771f9d81a2dfd3755
https://qiita.com/witchy/items/3a39b674097b86a44546


Ubuntu20にインストールしたkindで作業

-- 1. クラスタ作成

vim cluster.yml

apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
  - role: control-plane
  - role: worker
  - role: worker
  - role: worker


kind create cluster --name cluster01 --config cluster.yml


kind get clusters
kubectl get nodes
kubectl get pod -n kube-system


-- 2. DB作成

vim mysql01.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql01
spec:
  selector:
    matchLabels:
      app: mysql01
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql01
    spec:
      containers:
        - image: mysql:8.0.23
          name: mysql01
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: password
          ports:
            - containerPort: 3306
              name: mysql01


kubectl apply -f mysql01.yml
kubectl get all


-- 3. 動作確認

kubectl exec -it pod/mysql01-6dfcf2cd9b-xf6p1 -- bash
mysql -u root -p

 


-- 4. クリーンアップ

kubectl delete -f mysql01.yml
kubectl get all


kubectl get nodes
kind delete clusters cluster01

 

(19c)

https://blog.amedama.jp/entry/kind-k8s-in-docker


Ubuntu20にインストールしたkindで作業

-- 1. イメージ作成

cd

git clone https://github.com/oracle/docker-images.git

cd docker-images/OracleDatabase/SingleInstance/dockerfiles


ダウンロードファイル名:LINUX.X64_193000_db_home.zip

ダウンロードファイルは、解凍せずに以下のディレクトリ配下へ格納

~/docker-images/OracleDatabase/SingleInstance/dockerfiles/19.3.0


./buildContainerImage.sh -e -v 19.3.0

docker image ls

 


-- 2. クラスタ作成

vim cluster.yml

apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
  - role: control-plane
  - role: worker


kind create cluster --name cluster01 --config cluster.yml


kind get clusters
kubectl get nodes
kubectl get pod -n kube-system

作成したイメージをkindへロード
kind load docker-image oracle/database:19.3.0-ee --name cluster01


-- 3. DB作成

vim oracle01.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: oracle01
spec:
  selector:
    matchLabels:
      app: oracle01
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: oracle01
    spec:
      containers:
        - image: oracle/database:19.3.0-ee
          name: oracle01
          env:
            - name: ORACLE_SID
              value: orcl
            - name: ORACLE_PDB
              value: pdb1
            - name: ORACLE_PWD
              value: oracle
            - name: INIT_SGA_SIZE
              value: '1000'
            - name: INIT_PGA_SIZE
              value: '200'
            - name: ORACLE_EDITION
              value: enterprise
            - name: ORACLE_CHARACTERSET
              value: AL32UTF8
            - name: ENABLE_ARCHIVELOG
              value: 'false'
          ports:
            - containerPort: 1521
              name: oracle01
            - containerPort: 5500
              name: oracle02


kubectl apply -f oracle01.yml
kubectl get all

kubectl logs pod/oracle01-861b76d5fc-lh714 -f
※コンテナができるまでかなり時間がかかる


-- 4. 動作確認

kubectl exec -it pod/oracle01-868b76d5fc-lh724 -- bash
sqlplus / as sysdba

 


-- 5. クリーンアップ

kubectl delete -f oracle01.yml
kubectl get all


kubectl get nodes
kind delete clusters cluster01

 

 

 

(14)
https://qiita.com/higakin/items/f94b30686aabd0186d48

Ubuntu20にインストールしたkindで作業

-- 1. クラスタ作成

vim cluster.yml

apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
  - role: control-plane
  - role: worker
  - role: worker
  - role: worker


kind create cluster --name cluster01 --config cluster.yml


kind get clusters
kubectl get nodes
kubectl get pod -n kube-system


-- 2. DB作成

vim postgres01.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres01
spec:
  selector:
    matchLabels:
      app: postgres01
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: postgres01
    spec:
      containers:
        - image: postgres:14
          name: postgres01
          env:
            - name: POSTGRES_PASSWORD
              value: postgres
          ports:
            - containerPort: 5432
              name: postgres01


kubectl apply -f postgres01.yml
kubectl get all


-- 3. 動作確認

kubectl exec -it pod/postgres01-5f54bd4bb5-lg8zv -- bash
su - postgres
psql

 


-- 4. クリーンアップ

kubectl delete -f postgres01.yml
kubectl get all


kubectl get nodes
kind delete clusters cluster01

 

 

(2019)
Ubuntu20にインストールしたkindで作業

 

-- 1. クラスタ作成

vim cluster.yml

apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
  - role: control-plane
  - role: worker


kind create cluster --name cluster01 --config cluster.yml


kind get clusters
kubectl get nodes
kubectl get pod -n kube-system


-- 2. DB作成

vim sqlserver01.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sqlserver01
spec:
  selector:
    matchLabels:
      app: sqlserver01
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: sqlserver01
    spec:
      containers:
        - image: mcr.microsoft.com/mssql/server:2019-latest
          name: sqlserver01
          env:
            - name: ACCEPT_EULA
              value: 'Y'
            - name: SA_PASSWORD
              value: password
          ports:
            - containerPort: 1433
              name: sqlserver01


kubectl apply -f sqlserver01.yml
kubectl get all

 

-- 3. 動作確認

kubectl exec -it pod/sqlserver01-6fb84c8bfb-wgc8g -- bash

/opt/mssql-tools/bin/sqlcmd -S localhost -U sa

 


-- 4. クリーンアップ

kubectl delete -f sqlserver01.yml
kubectl get all


kubectl get nodes
kind delete clusters cluster01