実行手順
1. local永続ボリュームで使用するディレクトリの作成以下のコマンドでlocal永続ボリュームで使用するディレクトリを作成します。
minikube ssh
sudo mkdir -p /var/pgdata
sudo mkdir -p /var/superset
cd /var/superset
SECRET_KEY=`echo -e "import os; print(os.urandom(24).hex())" | python3`
cat << EOF | sudo tee superset_config.py
# Superset specific config
ROW_LIMIT = 5000
BABEL_DEFAULT_LOCALE='ja'
SUPERSET_WEBSERVER_PORT = 8088
# Flask App Builder configuration
# Your App secret key
#SECRET_KEY = '\2\1thisismyscretkey\1\2\e\y\y\h'
SECRET_KEY = '#####'
# The SQLAlchemy connection string to your database backend
# This connection defines the path to the database that stores your
# superset metadata (slices, connections, tables, dashboards, ...).
# Note that the connection information to connect to the datasources
# you want to explore are managed directly in the web UI
#SQLALCHEMY_DATABASE_URI = 'sqlite:////path/to/superset.db'
SQLALCHEMY_DATABASE_URI = 'postgresql://postgres:mypostgres@127.0.0.1/superset'
# Flask-WTF flag for CSRF
WTF_CSRF_ENABLED = True
# Add endpoints that need to be exempt from CSRF protection
WTF_CSRF_EXEMPT_LIST = []
# A CSRF token that expires in 1 year
WTF_CSRF_TIME_LIMIT = 60 * 60 * 24 * 365
# Set this API key to enable Mapbox visualizations
MAPBOX_API_KEY = ''
EOF
sudo sed -i "s/#####/$SECRET_KEY/" superset_config.py
exit
2. local永続ボリュームの作成
以下のコマンドでlocal永続ボリュームを作成します。
※PostgreSQLデータ用
cat << EOF > local-pg-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-pg-pv
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
storageClassName: local-storage
local:
path: /var/pgdata
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- minikube
EOF
kubectl apply -f ./local-pg-pv.yml
※superset用
cat << EOF > local-superset-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-superset-pv
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
storageClassName: local-storage
local:
path: /var/superset
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- minikube
EOF
kubectl apply -f ./local-superset-pv.yml
3. 永続ボリューム要求の作成
以下のコマンドで永続ボリューム要求を作成します。
※PostgreSQL用
cat << EOF > local-pg-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: local-pg-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-storage
resources:
requests:
storage: 5Gi
volumeName: local-pg-pv
EOF
kubectl apply -f ./local-pg-pvc.yml
※superset用
cat << EOF > local-superset-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: local-superset-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-storage
resources:
requests:
storage: 5Gi
volumeName: local-superset-pv
EOF
kubectl apply -f ./local-superset-pvc.yml
4. SupersetとPostgrelSQLのDeploymentの作成
以下のコマンドでsupersetとPostgreSQLを含むポッドと作成したlocal永続ボリュームを使用するDeploymentを作成します。
cat << EOF > superset-pg-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: superset-pg-deployment
labels:
app: superset-pg
spec:
replicas: 1
selector:
matchLabels:
app: superset-pg
strategy:
type: Recreate
template:
metadata:
labels:
app: superset-pg
spec:
containers:
- name: mypg
image: postgres:14-alpine
env:
- name: POSTGRES_DB
value: superset
- name: POSTGRES_PASSWORD
value: mypostgres
ports:
- containerPort: 5432
volumeMounts:
- name: pgdata
mountPath: /var/lib/postgresql/data
- name: superset
image: apache/superset:latest
command: ["/bin/sh","-c"]
args: ["pip install psycopg2 ; superset fab create-admin --username admin --firstname Superset --lastname Admin --email admin@superset.com --password admin ; superset db upgrade ; superset load_examples ; superset init ; /usr/bin/run-server.sh"]
env:
- name: PYTHONPATH
value: /opt
ports:
- containerPort: 8088
volumeMounts:
- name: superset
mountPath: /opt
volumes:
- name: pgdata
persistentVolumeClaim:
claimName: local-pg-pvc
- name: superset
persistentVolumeClaim:
claimName: local-superset-pvc
EOF
kubectl apply -f ./superset-pg-deployment.yml
5. サービスの作成
以下のコマンドでサービスを作成します。
cat << EOF > superset-service.yml
apiVersion: v1
kind: Service
metadata:
name: superset-service
spec:
selector:
app: superset-pg
ports:
- name: http
protocol: TCP
port: 8080
targetPort: 8088
- name: db
protocol: TCP
port: 5432
targetPort: 5432
EOF
kubectl apply -f ./superset-service.yml
6. Port-Fowardingで外部からアクセスできるようにする
kubectl port-forward --address 0.0.0.0 service/superset-service 8080:8080 5432:5432
ブラウザからhttp://<ホスト名:8080 にアクセスします。ユーザ名admin、パスワードadminでログインします。関連情報
・Apache Supersetのインストール方法、ダッシュボードやチャートの作成方法は以下のページを参照してください。Apache Supersetのまとめ
0 件のコメント:
コメントを投稿