可使用示例 YAML 文件部署具有永久数据存储的 Guestbook 应用程序。
Redis 主节点持久卷声明
文件
redis-leader-pvc.yaml
是一个引用命名存储类的持久卷声明示例。要使用此示例,请输入存储类的名称。
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: redis-leader-pvc spec: accessModes: - ReadWriteOnce storageClassName: tkg-storage-class-name resources: requests: storage: 2Gi
Redis 从节点持久卷声明
文件
redis-follower-pvc.yaml
是一个引用命名存储类的持久卷声明示例。要使用此示例,请输入存储类的名称。
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: redis-follower-pvc spec: accessModes: - ReadWriteOnce storageClassName: tkg-storage-class-name resources: requests: storage: 2Gi
Redis 主节点部署
文件
redis-leader-deployment.yaml
是一个具有持久卷的 Redis 主节点部署示例。
apiVersion: apps/v1 kind: Deployment metadata: name: redis-leader-deployment spec: selector: matchLabels: app: redis role: leader tier: backend replicas: 1 template: metadata: labels: app: redis role: leader tier: backend spec: containers: - name: leader image: redis:6.0.5 resources: requests: cpu: 100m memory: 100Mi ports: - containerPort: 6379 volumeMounts: - name: redis-leader-data mountPath: /data volumes: - name: redis-leader-data persistentVolumeClaim: claimName: redis-leader-pvc
Redis 从节点部署
文件
redis-follower-deployment.yaml
是一个具有持久卷的 Redis 从节点部署示例。
apiVersion: apps/v1 kind: Deployment metadata: name: redis-follower-deployment labels: app: redis spec: selector: matchLabels: app: redis role: follower tier: backend replicas: 1 template: metadata: labels: app: redis role: follower tier: backend spec: containers: - name: follower image: gcr.io/google_samples/gb-redis-follower:v2 resources: requests: cpu: 100m memory: 100Mi env: - name: GET_HOSTS_FROM value: dns ports: - containerPort: 6379 volumeMounts: - name: redis-follower-data mountPath: /data volumes: - name: redis-follower-data persistentVolumeClaim: claimName: redis-follower-pvc
Redis 主节点服务
文件
redis-leader-service.yaml
是一个 Redis 主节点服务示例。
apiVersion: v1 kind: Service metadata: name: redis-leader labels: app: redis role: leader tier: backend spec: ports: - port: 6379 targetPort: 6379 selector: app: redis role: leader tier: backend
Redis 从节点服务
文件
redis-follower-service.yaml
是一个 Redis 从节点服务示例。
apiVersion: v1 kind: Service metadata: name: redis-follower labels: app: redis role: follower tier: backend spec: ports: - port: 6379 selector: app: redis role: follower tier: backend
Guestbook 前端部署
文件
guestbook-frontend-deployment.yaml
是一个 Guestbook 前端部署示例。
apiVersion: apps/v1 kind: Deployment metadata: name: guestbook-frontend-deployment spec: selector: matchLabels: app: guestbook tier: frontend replicas: 3 template: metadata: labels: app: guestbook tier: frontend spec: containers: - name: php-redis image: gcr.io/google_samples/gb-frontend:v5 resources: requests: cpu: 100m memory: 100Mi env: - name: GET_HOSTS_FROM value: dns ports: - containerPort: 80
Guestbook 前端服务
文件
guestbook-frontend-service.yaml
是一个 Guestbook 前端负载均衡器服务示例。
apiVersion: v1 kind: Service metadata: name: guestbook-frontend labels: app: guestbook tier: frontend spec: type: LoadBalancer ports: - port: 80 selector: app: guestbook tier: frontend