Kubernetes(K8S) 应用部署

  • Kubernetes 应用部署

    部署是一种将镜像转换为容器,然后将这些镜像分配给Kubernetes集群中的Pod的方法。这也有助于设置应用程序集群,包括服务,pod,复制控制器和副本集的部署。可以通过这样一种方式来设置集群:部署在Pod上的应用程序可以相互通信。
    在此设置中,我们可以在一个应用程序的顶部进行负载平衡器设置,以将流量转移到一组Pod,然后它们与后端Pod通信。Pod之间的通信通过Kubernetes中内置的服务对象进行。
    application
  • Ngnix负载平衡器Yaml文件

    
    apiVersion: v1
    kind: Service
    metadata:
       name: oppv-dev-nginx
          labels:
             k8s-app: omni-ppv-api
    spec:
       type: NodePort
       ports:
       - port: 8080
          nodePort: 31999
          name: omninginx
       selector:
          k8s-app: appname
          component: nginx
          env: dev
    
  • Ngnix复制控制器Yaml

    
    apiVersion: v1
    kind: ReplicationController
    metadata:
       name: appname
    spec:
       replicas: replica_count
       template:
          metadata:
             name: appname
             labels:
                k8s-app: appname
                component: nginx
                   env: env_name
    spec:
       nodeSelector:
          resource-group: oppv
       containers:
          - name: appname
          image: IMAGE_TEMPLATE
          imagePullPolicy: Always
          ports:
             - containerPort: 8080
             resources:
                requests:
                   memory: "request_mem"
                   cpu: "request_cpu"
                limits:
                   memory: "limit_mem"
                   cpu: "limit_cpu"
                env:
                - name: BACKEND_HOST
                   value: oppv-env_name-node:3000
    
  • 前端服务Yaml文件

    
    apiVersion: v1
    kind: Service
    metadata:
       name: appname
       labels:
          k8s-app: appname
    spec:
       type: NodePort
       ports:
       - name: http
          port: 3000
          protocol: TCP
          targetPort: 3000
       selector:
          k8s-app: appname
          component: nodejs
          env: dev
    
  • 前端复制控制器Yaml文件

    
    apiVersion: v1
    kind: ReplicationController
    metadata:
       name: Frontend
    spec:
       replicas: 3
       template:
          metadata:
             name: frontend
             labels:
                k8s-app: Frontend
                component: nodejs
                env: Dev
    spec:
       nodeSelector:
          resource-group: oppv
       containers:
          - name: appname
             image: IMAGE_TEMPLATE
             imagePullPolicy: Always
             ports:
                - containerPort: 3000
                resources:
                   requests:
                      memory: "request_mem"
                      cpu: "limit_cpu"
                      limits:
                      memory: "limit_mem"
                      cpu: "limit_cpu"
                env:
                   - name: ENV
                   valueFrom:
                   configMapKeyRef:
                   name: appname
                   key: config-env
    
  • 后端服务Yaml文件

    
    apiVersion: v1
    kind: Service
    metadata:
       name: backend
       labels:
          k8s-app: backend
    spec:
       type: NodePort
       ports:
       - name: http
          port: 9010
          protocol: TCP
          targetPort: 9000
       selector:
          k8s-app: appname
          component: play
          env: dev
    支持的复制控制器Yaml文件
    apiVersion: v1
    kind: ReplicationController
    metadata:
       name: backend
    spec:
       replicas: 3
       template:
          metadata:
             name: backend
          labels:
             k8s-app: beckend
             component: play
             env: dev
    spec:
       nodeSelector:
          resource-group: oppv
          containers:
             - name: appname
                image: IMAGE_TEMPLATE
                imagePullPolicy: Always
                ports:
                - containerPort: 9000
                command: [ "./docker-entrypoint.sh" ]
                resources:
                   requests:
                      memory: "request_mem"
                      cpu: "request_cpu"
                   limits:
                      memory: "limit_mem"
                      cpu: "limit_cpu"
                volumeMounts:
                   - name: config-volume
                   mountPath: /app/vipin/play/conf
             volumes:
                - name: config-volume
                configMap:
                name: appname