在Kubernetes集群中扩展WordPress并访问单个PVC(持久性文件存储)的步骤如下:
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
spec:
replicas: 3
selector:
matchLabels:
app: wordpress
template:
metadata:
labels:
app: wordpress
spec:
containers:
- name: wordpress
image: wordpress:latest
ports:
- containerPort: 80
volumeMounts:
- name: wordpress-persistent-storage
mountPath: /var/www/html
volumes:
- name: wordpress-persistent-storage
persistentVolumeClaim:
claimName: wordpress-pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wordpress-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
apiVersion: v1
kind: Service
metadata:
name: wordpress-service
spec:
selector:
app: wordpress
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
kubectl apply -f wordpress-deployment.yaml
kubectl apply -f wordpress-pvc.yaml
kubectl apply -f wordpress-service.yaml
kubectl get pods
kubectl get pvc
kubectl get service
这样,我们就在Kubernetes集群中成功扩展了WordPress,并使用单个PVC进行持久性文件存储。
腾讯云相关产品推荐:
领取专属 10元无门槛券
手把手带您无忧上云