Сегодня будет пример деплоимента СУБД MySQL для Kubernetes.
3) Применяем kubectl create -f secret.yaml
4) mysql-deployment.yaml
Нам необходимо будет создать два файла.
secret.yaml - пароль для MySQL
mysql-deployment.yaml - деплои mysql
1) Генерим пароль для mysql
echo -n 'admin' | base64
2) Вставляем зашифрованое значение в secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: mysql-pass
type: Opaque
data:
password: YWRtaW4x
3) Применяем kubectl create -f secret.yaml
4) mysql-deployment.yaml
apiVersion: v1
kind: Service
metadata:
name: mysql-service
labels:
app: mysql
spec:
ports:
- port: 3306
selector:
app: mysql
tier: mysql
clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
labels:
app: mysql
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: mysql
labels:
app: mysql
spec:
selector:
matchLabels:
app: mysql
tier: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: mysql
tier: mysql
spec:
containers:
- image: mysql:5.6
name: mysql
resources:
requests:
memory: 100Mi
cpu: 300m
limits:
memory: 300Mi
cpu: 900m
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pvc
5) применяем kubectl apply -f mysql-deployment.yaml
6) Проверяем:
kubectl get secret
kubectl get pods
7) Заходим в Pod и логинимся в mysql
5) применяем kubectl apply -f mysql-deployment.yaml
6) Проверяем:
kubectl get secret
kubectl get pods
7) Заходим в Pod и логинимся в mysql
/# exec -ti mysql-549669d6c6-xgjbc -- /bin/bash
/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.44 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Комментариев нет:
Отправить комментарий