kubernetes实验挑战三(| Vote App | Redis | Postgresql DB | Deployment | service)

Deploy the given architecture to vote namespace.
kubernetes实验挑战三(| Vote App | Redis | Postgresql DB | Deployment | service)_第1张图片
1、Create a new namespace: name = ‘vote’

kubectl create ns vote

2、

  • Create new deployment. name: ‘worker’
  • image: ‘kodekloud/examplevotingapp_worker’
  • status: ‘Running’
kubectl create deployment worker --image kodekloud/examplevotingapp_worker

3、

  • Create a new service: name = vote-service
  • port = ‘5000’
  • targetPort = ‘80’
  • nodePort= ‘31000’
  • service endpoint exposes deployment ‘vote-deployment’
apiVersion: v1
kind: Service
metadata:
  name: vote-service
  namespace: vote
spec:
  type: NodePort
  selector:
    app.kubernetes.io/name: vote-deployment
  ports:
    - protocol: TCP
      port: 5000
      targetPort: 80
      nodePort: 31000

4、

  • Create a deployment: name = ‘vote-deployment’
  • image = ‘kodekloud/examplevotingapp_vote:before’
  • status: ‘Running’
kubectl create deployment vote-deployment --image kodekloud/examplevotingapp_vote:before -n vote

在这里插入图片描述

5、

  • New Service, name = ‘redis’
  • port: ‘6379’
  • targetPort: ‘6379’
  • type: ‘ClusterIP’
  • service endpoint exposes deployment ‘redis-deployment’
apiVersion: v1
kind: Service
metadata:
  name: redis-service
  namespace: vote
spec:
  selector:
    app.kubernetes.io/name: redis-deployment
  ports:
    - protocol: TCP
      port: 6379
      targetPort: 6379

6、
Create new deployment, name: ‘redis-deployment’

image: ‘redis:alpine’

Volume Type: ‘EmptyDir’

Volume Name: ‘redis-data’

mountPath: ‘/data’

status: ‘Running’

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: redis-deployment
  name: redis-deployment
  namespace: vote
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis-deployment
  template:
    metadata:
      labels:
        app: redis-deployment
    spec:
      containers:
      - image: redis:alpine
        name: redis-deployment
        volumeMounts:
        - mountPath: /data
          name: redis-data
      volumes:
      - name: redis-data
        emptyDir: {}

7、
Create new deployment. name: ‘worker’

image: ‘kodekloud/examplevotingapp_worker’

status: ‘Running’

kubectl create deployment worker --image kodekloud/examplevotingapp_worker -n vote

8、
Create new service: ‘db’

port: ‘5432’

targetPort: ‘5432’

type: ‘ClusterIP’

---
apiVersion: v1
kind: Service
metadata:
  name: db
  namespace: vote
spec:
   type: ClusterIP
   ports:
     - port: 5432
       targetPort: 5432
   selector:
       app: db-deployment

       

9、
Create new deployment. name: ‘db-deployment’

image: ‘postgres:9.4’ and add the env: ‘POSTGRES_HOST_AUTH_METHOD=trust’

Volume Type: ‘EmptyDir’

Volume Name: ‘db-data’

mountPath: ‘/var/lib/postgresql/data’

status: ‘Running’

# kubectl create deployment db-deployment --image=postgres:9.4 --dry-run=client -o yaml -n vote > db-deployment.yaml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: db-deployment
  name: db-deployment
  namespace: vote
spec:
  replicas: 1
  selector:
    matchLabels:
      app: db-deployment
  template:
    metadata:
      labels:
        app: db-deployment
    spec:
      containers:
      - image: postgres:9.4
        name: postgres
        env:
          - name: POSTGRES_HOST_AUTH_METHOD
            value: trust
        volumeMounts:
          - mountPath: /var/lib/postgresql/data
            name: db-data
      volumes:
        - name: db-data
          emptyDir: {}




10、

Create new deployment, name: ‘result-deployment’

image: ‘kodekloud/examplevotingapp_result:before’

status: ‘Running’

 kubectl create deployment result-deployment --image=kodekloud/examplevotingapp_result:before -n vote

11、
port: ‘5001’

targetPort: ‘80’

NodePort: ‘31001’

---
apiVersion: v1
kind: Service
metadata:
  name: result-service
  namespace: vote
spec:
  type: NodePort
  ports:
    - port: 5001
      targetPort: 80
      nodePort: 31001
  selector:
    app: result-deployment

    

你可能感兴趣的:(数据库,kubernetes,redis)