- Kubernetes Deployment 配置(oceanbase-deployment.yaml)
# oceanbase-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: oceanbase-deployment
spec:
replicas: 1
selector:
matchLabels:
app: oceanbase
template:
metadata:
labels:
app: oceanbase
spec:
nodeSelector: # 确保调度到有PV的节点
kubernetes.io/hostname: node1 # 如果是固定服务器磁盘需要固定节点
containers:
- name: oceanbase
image: registry.cn-hangzhou.aliyuncs.com/qiluo-images/oceanbase-ce:latest
env:
- name: OB_MEMORY_LIMIT
value: "12G"
- name: OB_SYSTEM_MEMORY
value: "3G"
- name: OB_CLUSTER_NAME
value: "OB_PROD_CLUSTER"
- name: OB_ROOT_PASSWORD
value: "6LuEpJaMudHd5yRc"
volumeMounts:
- mountPath: /root/ob/data
name: ob-data
- mountPath: /root/ob/clog
name: ob-clog
- mountPath: /etc/oceanbase
name: ob-config
volumes:
- name: ob-data
persistentVolumeClaim:
claimName: ob-data-pvc
- name: ob-clog
persistentVolumeClaim:
claimName: ob-clog-pvc
- name: ob-config
persistentVolumeClaim:
claimName: ob-config-pvc
- Kubernetes Service 配置(oceanbase-service.yaml)
apiVersion: v1
kind: Service
metadata:
name: oceanbase-service
spec:
selector:
app: oceanbase
ports:
- name: sql
port: 2881
targetPort: 2881
nodePort: 32681 # NodePort方式暴露
- name: metrics
port: 2882
targetPort: 2882
- name: rpc
port: 3881
targetPort: 3881
type: NodePort # 生产环境建议使用LoadBalancer
- PersistentVolumeClaim (oceanbase-pvc.yaml)
# oceanbase-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ob-data-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Gi
storageClassName: local-storage
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ob-clog-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 200Gi
storageClassName: local-storage
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ob-config-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
storageClassName: local-storage
4.手动创建 PV(适合无 StorageClass 的环境)oceanbase-pv.yaml
# oceanbase-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: ob-data-pv
spec:
capacity:
storage: 100Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /data/oceanbase/data
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node1 # 替换为实际节点名 # 如果是固定服务器磁盘需要固定节点
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: ob-clog-pv
spec:
capacity:
storage: 200Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /data/oceanbase/clog
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node1 # 如果是固定服务器磁盘需要固定节点
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: ob-config-pv
spec:
capacity:
storage: 20Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /data/oceanbase/config
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node1 # 如果是固定服务器磁盘需要固定节点
- 部署步骤
mkdir /data/oceanbase/{data,clog,config} -p
chmod 777 /data/oceanbase/{data,clog,config}
# 1. 创建PV和PVC
kubectl apply -f oceanbase-pv.yaml
kubectl apply -f oceanbase-pvc.yaml
# 2. 验证存储
kubectl get pv
kubectl get pvc # 应全部显示Bound状态
# 3. 部署OceanBase
kubectl apply -f oceanbase-deployment.yaml
kubectl apply -f oceanbase-service.yaml
# 4. 检查状态
kubectl get pods -w
或者
kubectl get pods -n dev -o wide -A
查看日志
kubectl logs -f <pod-name> -c oceanbase --tail=100
5.进入容器执行
docker exec -it <pod-name> /bin/bash
obclient -h127.0.0.1 -P2881 -uroot@sys -A
修改用户名
ALTER USER root IDENTIFIED BY '6LuEpJaMudHd5yRc';
此时此刻就连接成功啦
获取访问IP(根据实际环境调整)
kubectl get svc oceanbase

>**关键调整说明
存储配置:
必须使用 持久化存储(PV/PVC),推荐 SSD/NVMe
多节点部署时需要共享存储(如 Ceph RBD、NFS)
高可用改进:
# 在Deployment中增加
```yaml
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: oceanbase
topologyKey: "kubernetes.io/hostname"
生产环境建议:
使用 StatefulSet 替代 Deployment(稳定网络标识)
通过 ConfigMap 管理配置文件:
volumes:
- name: ob-config
configMap:
name: oceanbase-config
网络优化:
若需跨节点通信,使用 Headless Service
监控端口建议通过 Ingress 或 ServiceMesh 暴露
故障排查命令
# 检查资源限制
kubectl describe pod <pod-name> | grep -A 10 "Limits"
# 进入容器调试
kubectl exec -it <pod-name> -- bash
obd cluster list
# 查看事件日志
kubectl get events --sort-by=.metadata.creationTimestamp
请根据您的实际 Kubernetes 环境(如存储类名称、网络插件等)调整配置。生产部署前务必在测试环境验证。