安装Mendix Operator手册(Public Cloud VPC版)

Mendix与腾讯云携手推动中国低代码行业发展,此文章解释如何在腾讯公有云VPC网络环境下安装Mendix Operator

安装前准备工作

在安装Mendix Operator前需要准备好以下的云资源:

  • VPC私有网络:VPC, Subnet, NAT Gateway(用于VPCK8S 节点访问公网)
  • TKE容器服务集群:一个K8S集群
  • PostgreSQL 数据库:创建一个实例,并在实例中新建一个数据库
  • COS 存储桶 2个存储桶,一个用来存放Mendix MDA文件(公有读私有写权限),另一个给Mendix App使用(私有读写权限)
  • TCR或者CCR镜像仓库(Docker镜像仓库):需设置一个长期有效的访问TOKEN或密码
  • CLB负载均衡:一个负载均衡实例供Ingress Controller 使用,根据需求可选择内网或公网类型
  • Linux管理机器:预装kubectl(根据K8S集群管理账号进行配置,配置TKE kubeconfig),Bash

安装Ingress Controller

如果集群中没有默认的Ingress Controller,需要手动安装Ingress Controller,有两种方式可选:

方式1)挂载已有CLB,私网CLB或者公网CLB。


# 创建命名空间

kubectl create ns nginx-ingress

# YAML mirror 到了 COS,访问比较快,加入了 annotations 标签

wget https://mendix-1302743899.cos.ap-shanghai.myqcloud.com/ingress/nginx-ingress-deployment.yaml

vim nginx-ingress-deployment.yaml

# 找到 annotations,在 service.kubernetes.io/tke-existed-lbid: 后填入CLB ID

kubectl apply -f ./nginx-ingress-deployment.yaml


确认Ingress Controller已经分配到external IP,根据CLB类型可能是私网IP也可能是公网IP。

方式2)部署ingress controller的时候,系统自动创建公网IP的CLB,付费方式为按量付费,默认宽带为10M。


# 创建命名空间

kubectl create ns nginx-ingress

kubectl apply -f

https://raw.githubusercontent.com/TencentCloudContainerTeam/manifest/master/nginx-ingress/nginx-ingress-deployment.yaml -n nginx-ingress

# 访问raw.githubusercontent.com不稳定,有时访问不了,可以多试几次


集群里安装Mendix Operator

1.运行安装脚本

在装了kubectl并且配置了kubeconfig的管理机器上运行安装脚本

curl -s https://mendix-1302743899.cos.ap-shanghai.myqcloud.com/scripts/install-script-standalone | bash -s <你的namespace名字>

2. 运行配置脚本

curl -o post-install-script https://mendix-1302743899.cos.ap-shanghai.myqcloud.com/scripts/post-install-script-tce

chmod  +x post-install-script

./post-install-script <你的namespace名字>

3. 初始化Operator

第一次配置选1,以后发现参数配错了 要改配置参数选2

4. 配置数据库

 1Postgres

设置plan名(名字可以自定义,但是不能用下横线 “_”

输入数据库的内网IP和端口

输入提前在Postgres创建好的数据库 tke2(名字可以自定义)
注意: 不能用Postgres默认自带的数据库postgres,必须自己创建一个

输入登录用户和密码

是否启用TLS选 2)No

注意:strict TLS模式只能用于在Mendix 8.15.2(或更高版本)中创建的应用程序,更早的Mendix版本在验证TLS证书时将无法启动。

5. 配置文件存储

 4) COS (existing bucket)

之前创建INFRA的时候创建了一个Mendix App COS bucket保存Mendix App的静态文件,填入bucket的访问地址(VPC内部机器访问会自动解析成内网IP)。

输入有读写权限的用户的secret IDsecret key

6. 配置Ingress

域名根据客户需求,这个域名就是客户发布的Mendix App的访问域名,可以是内网域名也可以是公网域名。

注意:这里设置的test.com是域名后缀,如果在步骤3.1CR YAML中不设置自定义的域名sourceURLMendix Operator会用这里的域名test.comCR YAML里面的App Name拼接成一个完整的域名

是否启用TLS,我们测试没有启用,如果需要启用,需要配置ingress的证书。

​​​​7. 配置镜像库

 1Generic registry with authentication

这个是用来上传Mendix build pod制作好的用户Mendix AppDocker image

 

输入镜像库地址,用户名和密码

如果仓库地址是mendix.tencentcloudcr.com/mendix-app/firstapp (firstapp是上面创建的镜像仓库名,也就是自定义的Docker image名字),URL填 mendix.tencentcloudcr.com/mendix-app,Registry name填firstapp。
注意: URL:mendix.tencentcloudcr.com/mendix-app 结尾没有/,有/会出错

是否添加到default SA,选 1) Yes

注意:如果使用TCR公网访问需要把TKE所在VPC网络的NAT GATEWAY公网IP加到白名单里面TKE NODE通过NAT GATEWAY访问公网

8. 配置代理

 2No

9. ​​​​​​绑定ingress class name

给mendix-operator-configuration这个operatorconfiguration资源打一个补丁,让它使用上面步骤创建的ingress controller。


kubectl patch operatorconfiguration mendix-operator-configuration --type='json' -p='[{"op": "add", "path": "/spec/endpoint/ingress/annotations",

"value":{"kubernetes.io/ingress.class":"nginx","nginx.ingress.kubernetes.io/proxy-body-size":"500m"}}]' -n <你的namespace名字>

 


10. 添加Mendix Operator的license

没有安装licenseoperator只能使用一个月,并且有功能限制,手动添加license的步骤如下,license keybase64格式,LS0开头。

注意每个license颁发的时候对应一个namespace不能用于其他名字的namespace否则会导致激活失败licenseStatus还是处于trial mode如果需要在多个namespace导入license需要申请每个namespace自己的license


wget https://mendix-1302743899.cos.ap-shanghai.myqcloud.com/scripts/add-operator-license

vim add-operator-license

# 修改 license_key="LS0....."

# 修改 mendix_operator_namespace="<你的namespace名字>"

chmod +x ./add-operator-license && ./add-operator-license


例如:

 

 

11. 查看Operator license导入情况

按照下面第3步骤创建好MendixApp之后可以查看Operator状态:

kubectl get mendixapps.privatecloud.mendix.com <MendixApp名字> -o yaml -n <你的namespace名字> | grep Licensed

如果licenseStatus modeLicensed就说明导入证书成功,每个证书对应唯一的namespace,每个namespace都需要单独导入operator证书。


如果查看完整的yaml也可以看到 licenseStatus modeLicensed

kubectl get mendixapps.privatecloud.mendix.com <MendixApp名字> -o yaml -n <你的namespace名字>

部署Mendix App工程

1. 修改MendixApp custom resource模版

下面是根据官方模板修改的模板:


按照需求改一些参数:

vim mendixapp-cr-<mode>.yaml

apiVersion: privatecloud.mendix.com/v1alpha1

kind: MendixApp

metadata:

  name: helloworld # 自定义名

  namespace: tke2 # operator的命名空间如果需要在多个ns里面部署App需要在每个ns里面安装一遍operator

spec:

  database:

    servicePlan: tke2-db # 之前创建的DB plan

  storage:

    servicePlan: tke2-file # 之前创建的Storage plan

  mendixRuntimeVersion: 8.12.1.3458 # 版本需要跟Studio Pro的版本一致我们提供指定的studio pro版本给中国用户下载下载链接见文章结尾处

  sourceURL: http://mendixcos-pub-xxxxxxx.cos.chongqing.cospub.mxx-vx-poc-xxx.tcecloud.fsphere.cn/StartupApp_20200831_0907.mda # studio pro创建的App MDA文件上传到之前创建的share bucket可以免密匿名访问必须免密),这里填bucket MDA文件路

  appURL: helloworld.test.com # 这个域名是前面配置ingress设置的test.com加了一个前缀

  #tls: # 可选参数,可以被省略:设置一个自定义TLS配置来覆盖默认的operator配置

    # 为Mendix App启用或关闭TLS

    #enableTLS: true

    # 一个已经存在的包含TLS证书的kubernetes.io/tls secret名字

    #secretName: mendixapp-cert

  replicas: 1

  resources:

    limits:

      cpu: 500m

      memory: 512Mi

    requests:

      cpu: 500m

      memory: 512Mi

  runtime:

    logAutosubscribeLevel: INFO

    mxAdminPassword: xxxxxxx # 设置MendixAdmin user的密码base64

    dtapMode: P # 开发测试环境选D生产环境选P如果选P就需要配置下面runtimeLicense这四行也就是Mendix Runtimelicense

    runtimeLicense:

      type: offline

      id: xxxxx-xxxx-xxxx-xxxx-xxxxxxx # 收到的license ID

      key: LS0xxxxxxxxxxxxxxxx # 收到的license keybase64格式LS0

    # Mendix Runtime Jetty options, in JSON format; validated and applied by the mx-m2ee-sidecar container

    jettyOptions: |-

      {

        "max_form_content_size": 10485760,

        "use_blocking_connector": false

      }

    # All custom Mendix Runtime parameters go here, in JSON format; validated and applied by the mx-m2ee-sidecar container

    # 如果Mendix App 工程里面定义了常量,这儿没有赋值的话,runtime会启动不起来。详细步骤请参考:https://docs.mendix.com/developerportal/deploy/private-cloud-operator#set-app-constants

    customConfiguration: |-

      {

        "ScheduledEventExecution": "SPECIFIED",

        "MyScheduledEvents": "MyFirstModule.MyScheduledEvent",

        "MicroflowConstants":"{\"MyFirstModule.Constant\":\"1234\",\"Atlas_UI_Resources.Atlas_UI_Resources_Version\":\"2.5.4\"}"

      }


官方帮助文档如下里面包括了tls的证书选项如果需要启用Mendix App https可以参考:https://docs.mendix.com/developerportal/deploy/private-cloud-operator

1.1 ​​​​​​​为Mendix App启用https (可选)

需要在Ingress绑定tls证书,tls证书推荐用商业证书(需要单独购买),如果用自签证书有些浏览器(例如Chrome)会报错不让访问。

前面"​​​​​​​6.配置Ingress"这步启用ingress TLS

在所在的namespace创建tls证书对应的secret,这里secret名字mendixapp-cert可以自定义,但需跟Mendix App CR模板里面的名字一致。

kubectl create secret tls mendixapp-cert --key tls.key --cert tls.crt -n <你的namespace名字>

再次编辑CR yaml模板文件,去掉下面3行前面的注释符号#。

vim mendixapp-cr-<mode>.yaml

​​​​​​​2. 创建MDA文件

特别注意,在Studio Pro要把Project security level设置为ProductionApp工程才能部署到生产环境 (P mode),参考https://docs.mendix.com/refguide/project-security

Studio Pro 双击左侧Project下面Security, 在弹出的框Security level选择Production , OK保存设置。

  

Security配完可以创建MDA:点击project ->  Create Deployment Package ,弹出来的框Versioned选择No,点OK保存MDA文件。

3. 部署Mendix App custom resource YAML

kubectl apply -f mendixapp-cr-<mode>.yaml -n <你的namespace名字>

特别注意指定的命名空间必须是和operator同一个namespace如果需要在多个命名空间里面部署App需要在每个namespace里面安装一遍operator

build pod会把MDA文件buildDocker image上传到上面配置的Docker镜像仓库

然后会自动用这个image部署APP,下面对应UserAPP已经部署好了。

这时候就可以用Ingress域名helloworld.test.com访问APP了,前提是配置DNS A记录。

​​​​​​​4. 确认Mendix Runtime(App) license导入成功

查看App pod的日志,如果里面有license的准确信息说明导入证书成功。

中国地区Studio Pro下载地址

中国客户Studio Pro的下载地址是:https://mendix-1302743899.cos.ap-shanghai.myqcloud.com/studio_pro/Mendix-8.12.1.3458-Setup.exe ,是目前支持的最新版本

谢谢阅读!

猜你喜欢

转载自blog.csdn.net/Mendix/article/details/113615933