使用範例 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