手册
Kubernetes 应用

Kubernetes 应用

MegaEase Cloud 平台可以托管用户的服务器,支持快速部署并管理常见的软件服务和云原生应用,让用户以此获得不被平台锁定,低成本,高可用的云原生平台。

本文档介绍如何在 MegaEase Cloud 平台上部署 Kubernetes 应用。

安装 Kubernetes

安装 Kubernetes App 的前提,需要提前在中间件服务里安装 Kubernetes 。

  1. 进入Services页面
  2. 点击Create Service,选择 Kubernetes

  1. 选择可用版本
  2. 名字可用自动生成,也可手动填写
  3. 选择 Etcd Nodes Count、Control Plane Count、Kube Node Count
  4. 根据以上配置,选择对应的Host节点
  5. 选择网络插件
  6. 目录如无必要,尽量不修改
  7. 点击Create创建 Kubernetes 服务

安装 Kubernetes App

  1. 进入 App 页面
  2. 点击 Create App,选择 Kubernetes App

  1. 有三种方式可供选择(不论哪种方式,最后均是生成YAML文件)
    1. 是从本地上传 App YAML 文件
    2. 编辑提供的模版文件
    3. 填写表单
  2. 以模版文件为例,我们提供了简单模版

  1. 如 Mesh App 一样,我们用较为复杂的 TakeoutApp 来作为示例创建Kubernetes App。

  1. 点击 Submit
  2. Cluster Name 选择对应的Kubernetes集群

  1. 如果需要Mesh治理功能,Enable 即可,详情可见 Mesh 页
  2. 点击 Next

  1. 点击 Create 即可创建Stack

此外,同样的 Stack 我们可以用填写表单的方式创建:

  1. 在上述第3步选择 Create Step by Step,填写表单如下

  1. 点击 Next 进入Component创建页

  1. 点击 Components 下面的+号,选择 Component,填写 order-mesh 的表单

  1. 点进 Next 填写命令与资源相关表单

  1. 点进Next填写流量与配置相关表单

  1. 点进OK即保存好order-mesh

  1. 剩下的 restaurant-mesh 与 delivery-mesh 使用类似步骤即可创建完整的 TakeoutApp Stack。

附录

TakeoutApp 完整代码可见:Mesh Example (opens in a new tab).

我们将以 TakeoutApp 为例子,将不够直观的配置用注释说明,component 里没有直接使用的配置放在 order-mesh 里作为例子。

takeoutapp.yaml:

name: takeoutapp
 
 
# Kubernetes namespace.
namespace: takeoutapp
 
 
cluster_name: kubernetes2c221c475
description: An application comprising of order, restaurant, delivery.
 
 
 # Mesh related config.
easemesh:
  enable: false
 
 
# Health check related config.
health_check_retry_times: 3
health_check_interval: 10s
 
 
# When stack status is under retrying state, it should delete old resources
# and redeploy it. The RetryMaxTime is maximum times value of retry deploy
# resource. When retrying times exceed this value, the stack status would
# changed to failed status
retry_max_time: 3
retry_interval: 30s
 
 
# Env applied to all components.
env_variables:
- name: STACK_NAME
  value: takeoutapp
 
 
# pulse event frequency can be specified by user for advance option
# default value is 10 seconds
pulse_event_interval: 10s
 
 
# image_pull_secret_names is a credentials which kubernetes will use it to pull
# the image from the private registry. the value is copied from the cluster configuration.
image_pull_secret_names: {}
 
 
components:
 
 
# Order
- name: order-mesh
  enable: true
  image: megaease/meshdemo
  image_version: latest
  instance_count: 1
 
  # IfNotPresent, Never, Always
  image_pull_policy: IfNotPresent
 
 
  # Stateless creates Deployment, Stateful creates StatefulSet
  type: Stateless
 
 
  # The first element of array map to kubernetes v1/Container command to entrypoint array,
  # the remains elements map to  v1/Container args to entrypoint array.
  command: []
 
 
  # liveness_probe_command is used to check if the component is healthy.
  liveness_probe_command: []
  # readiness_probe_command is used to check if the component is ready for traffic.
  readiness_probe_command: []
 
 
  # Current component launched after launching dependency components.
  dependency_components: []
 
 
  # Parts of volume from Kubernetes, so the naming convention is camel case.
  # All types are the same as Kubernetes.
  volumeMounts: []
  volumeClaimTemplates: []
  volumes: []
 
 
  # Health check config for the component.
  initial_delay_seconds: 10
  probe_timeout_seconds: 5
  probe_period_seconds: 5
  health_check_retry_times: 3
  health_check_interval: 10s
 
 
  # The flag indicate whether component service is type NodePort.
  is_node_port: true
 
 
  annotations:
    component_name: order-mesh
 
 
  named_ports:
  - name: http
    port: 80
  env_variables:
  - name: SERVICE_NAME
    value: order-mesh
  - name: ZIPKIN_URL
    value: https://monitor.megaease.com:32430/report/application-tracing-log
  resource_require:
    cpu: 200m
    memory: 256Mi
  resource_limit:
    cpu: 1200m
    memory: 2048Mi
  configurations:
  - key: listenPort
    value: "7700"
    use_as_file: /etc/port_config
    is_sub_path: true
  - key: listenAddr
    value: 127.0.0.1
    use_as_file: /etc/address_config
    is_sub_path: true
 
 
# Restaurant
- name: restaurant-mesh
  enable: true
  image: megaease/meshdemo
  image_version: latest
  type: Stateless
  instance_count: 1
  named_ports:
  - name: http
    port: 80
  env_variables:
  - name: SERVICE_NAME
    value: restaurant-mesh
  - name: ZIPKIN_URL
    value: https://monitor.megaease.com:32430/report/application-tracing-log
  resource_require:
    cpu: 200m
    memory: 1Gi
  resource_limit:
    cpu: 2000m
    memory: 3Gi
  configurations:
  - key: listenPort
    value: "8800"
    use_as_file: /etc/port_config
    is_sub_path: true
  - key: listenAddr
    value: 0.0.0.0
    use_as_file: /etc/address_config
    is_sub_path: true
 
 
# Delivery
- name: delivery-mesh
  enable: true
  image: megaease/meshdemo
  image_version: latest
  type: Stateless
  instance_count: 1
  named_ports:
  - name: http
    port: 80
  env_variables:
  - name: SERVICE_NAME
    value: delivery-mesh
  - name: ZIPKIN_URL
    value: https://monitor.megaease.com:32430/report/application-tracing-log
  resource_require:
    cpu: 200m
    memory: 256Mi
  resource_limit:
    cpu: 1200m
    memory: 2048Mi
  configurations:
  - key: listenPort
    value: "9900"
    use_as_file: /etc/port_config
    is_sub_path: true
  - key: listenAddr
    value: 127.0.0.1
    use_as_file: /etc/address_config
    is_sub_path: true