gpt4 book ai didi

k8s keycloack not persistent(K8S密钥盒不是永久性的)

转载 作者:bug小助手 更新时间:2023-10-28 21:28:27 25 4
gpt4 key购买 nike



I have a problem with my keycloack deployed on k8s, every time a new pods is spawned or recreated pod, keycloack data is lost, how can I make keycloack persistent? This is my setup:

我在K8上部署的密钥盒有问题,每次产生或重新创建新的实例时,密钥盒数据都会丢失,如何使密钥盒持久化?这是我的设置:


Manifest:

货单:


---
apiVersion: "apps/v1"
kind: "Deployment"
metadata:
name: kc-dp
labels:
app: kc
spec:
selector:
matchLabels:
app: keycloak
template:
metadata:
labels:
app: kc
spec:
containers:
- name: kc-container
image: quay.io/keycloak/keycloak:21.1.1
args: ["start-dev"]
ports:
- containerPort: 8080
envFrom:
- configMapRef:
name: kc-env
- secretRef:
name: kc-secret
volumeMounts:
- mountPath: /opt/jboss/keycloak/startup/elements
name: kc-ps
volumes:
- name: kc-ps
persistentVolumeClaim:
claimName: keycloak-pv-claim
---
apiVersion: v1
kind: Service
metadata:
name: keycloak-service
spec:
type: NodePort
selector:
app: keycloak
ports:
- port: 8080
targetPort: 8080
nodePort: 30000

Persistent Volume:

持久卷:


apiVersion: v1
kind: PersistentVolume
metadata:
name: kc-pv
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"


Persistent Volume Claim:

永久批量申请:


apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: kc-pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi


Config map:

配置映射:


DB_DATABASE=kc_db

Secret map

秘密地图


DB_VENDOR=MYSQL
DB_ADDR=mysql-svc
DB_USER=foo
DB_PASSWORD=fooo
KEYCLOAK_ADMIN=admin
KEYCLOAK_LOGLEVEL=ALL
KEYCLOAK_ADMIN_PASSWORD=pwd

How could I solve the problem? Also it seems that keycloack doesn't save anything on my mysql DB.

我该怎么解决这个问题?另外,似乎keycloack不保存任何东西在我的mysql数据库。


更多回答

The hostPath volume isn't tied to a specific node. If your Pod gets deleted and recreated on a different node, it will try using that same directory on the new node and find it empty. Can you let the cluster create the PersistentVolume, rather than creating it yourself? (Also consider using a StatefulSet and not a Deployment for this scenario.)

主机路径卷未绑定到特定节点。如果您的Pod被删除并在不同的节点上重新创建,它将尝试在新节点上使用相同的目录,但发现它是空的。您可以让集群创建PersistentVolume,而不是自己创建它吗?(还可以考虑在此场景中使用状态集,而不是部署。)

优秀答案推荐

The answer was simpler than it seemed, following the keyclock guide and setting the appropriate environment variables I managed to persist my keyclock.

答案比看起来更简单,我按照键盘时钟的指导,设置了适当的环境变量,成功地保存了我的键盘时钟。


https://www.keycloak.org/getting-started/getting-started-kube

Https://www.keycloak.org/getting-started/getting-started-kube


https://www.keycloak.org/server/all-config

https://www.keycloak.org/server/all-config


thank you, all.

谢谢大家。


更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com