使用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数据库了。