使用kubectl命令行工具連接到Kubernetes集群的master節點。
創建一個Redis的Deployment資源,可以使用以下yaml配置文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-deployment
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis
ports:
- containerPort: 6379
kubectl apply -f redis-deployment.yaml
apiVersion: v1
kind: Service
metadata:
name: redis-service
spec:
selector:
app: redis
ports:
- protocol: TCP
port: 6379
targetPort: 6379
type: LoadBalancer
kubectl apply -f redis-service.yaml
kubectl get deployments
kubectl get services
kubectl exec -it <redis-pod-name> -- redis-cli
> SET key value
> GET key
這樣就可以在Kubernetes集群中安裝和管理Redis數據庫了。