Kubernetes - 应用部署
部署是一种将镜像转换为容器,然后将这些镜像分配到 Kubernetes 集群中的 pod 的方法。 这也有助于设置应用程序集群,包括服务、pod、复制控制器和副本集的部署。 可以将集群设置为部署在 pod 上的应用程序可以相互通信。
在此设置中,我们可以在一个应用程序之上设置负载均衡器,将流量转移到一组 Pod,然后它们与后端 Pod 通信。 Pod 之间的通信是通过 Kubernetes 内置的服务对象进行的。
Nginx 负载均衡器 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