Tutorial
Make Application Files
Make Images
The traditional industry application need to be made into a Docker image first. We reconmended to make the application into Docker image by Dockerfile, please refer Docker Documentation to make an image.
Make YAML Files
After making the application into Docker image, the next step is to make YAML files. The types of instance in YAML files that iManager supports to create are including Service, Deployment, Statefulset, Job, PersistentVolumeClaim, ServiceAccount, and ConfigMap.
The rules of YAML please see: https://kubernetes.io/docs/concepts/
Users can control the display of application by configuring the attributes ‘StatefullSet’ and ‘annotation’ in ‘Service’ instance and ‘Deployment’ instance. The supported parameters are lisetd in the Appendix.
Notes:
Select UTF-8 encoding when making YAML files.
Appendix
-
The attribute configuration in YAML.
The annotation attribute in Service:
Name Description addressReg The format of service address, the default format is 'http://${SERVICE_IP}:${NODE_PORT}' showPorts The targetPort of the service address when a service has multiple ports The labels attribute in Service:
Name Description entrance Whether to use service address as the access entrance. The service address is the access entrance when the value is true, the value is 'false' by default. entrance-port The targetPort of the access entrance when a service has multiple ports. Only works when the value of entrance is true. Example:
apiVersion: v1 kind: Service metadata: name: mysql labels: entrance: "true" entrance-port: "3306" annotations: addressReg: "jdbc:mysql://mysql:3306" showPorts: "[3306]" spec: ports: - port: 3306 selector: app: mysql type: NodePort
The annotation attribute in Deployment and StatefulSet:
Name Description scale Whether to support scaling, the value is 'yes' by default. Configure the value to 'unscalable' to hide the scaling button. console Whether to support command pad, the value is 'yes' by default. Configure the value to 'noconsole' to hide the command pad. description The description in the service list. accountInfo The account information, supports html format. topoProperty The style of topological diagram, string with json format. {
name: the Deployment/StatefulSet name of the service.
isPivot: whether to be the center point.
index: sort number, ‘1’ is north side, sort by clockwise(the default is sorting by the lexicographic order of the name).
parents: [{
name: the Deployment/StatefulSet name of the directed service.
description: the description of the association between services.
}]
}Example:
apiVersion: apps/v1 kind: Deployment metadata: labels: app: mysql name: mysql annotations: scale: unscalable console: noconsole description: MySQL Database accountInfo: "<p>Username/Password:</p><p> root/supermap</p>" topoProperty: "{'name':'mysql','isPivot':'false','index':1,'parents':[{'name':'phpmyadmin','description':'The UI of Database management}]}" spec: selector: matchLabels: app: mysql template: metadata: labels: app: mysql spec: containers: - env: - name: MYSQL_ROOT_PASSWORD value: supermap image: registry.ispeco.com/supermap/mysql:5.7.12 name: mysql imagePullPolicy: Always restartPolicy: Always
The attribute in PersistentVolumeClaim:
Name Description storageClassName The name of storageClass, the format is 'appset-storage-class-${GROUP_TYPE}'. Example:
apiVersion: v1 kind: PersistentVolumeClaim metadata: labels: type: mysql name: pvc-nfs-mysql-data-${appsetId} spec: storageClassName: appset-storage-class-${GROUP_TYPE} accessModes: - ReadWriteMany resources: requests: storage: 1Gi
-
Placeholder list
Use the following placeholders in YAML file, the placeholders will be replaced automatically when creating applications.
Name Description ${appsetId} The ID of the application
Example: the name of PersistentVolumeClaim
name: pvc-nfs-mysql-data-${appsetId}
${SERVICE_IP} The IP of service address
Example: add annotation in Service
addressReg: “jdbc:mysql://${SERVICE_IP}:8080”
${SERVICE_NAME} The name of the service
Example: add annotation in Service
addressReg: “jdbc:mysql://${SERVICE_NAME}:8080”
${NODE_PORT} The nodePort of the service
Example: add annotation in Service
addressReg: “jdbc:mysql://127.0.0.1:${NODE_PORT}”
${TARGET_PORT} The targetPort of the service
Example: add annotation in Service
addressReg: “jdbc:mysql://127.0.0.1:${TARGET_PORT}”
${IMAGE_PULL_POLICY} The policy of pulling images
Example: imagePullPolicy: ${IMAGE_PULL_POLICY}
${IMAGE_PULL_SECRET} The image pull secret
Example: imagePullSecrets:
- name: ”${IMAGE_PULL_SECRET}”${REGISTRY_URL} The registry address
Example: image: ${REGISTRY_URL}supermap/mysql:5.7.12
${GIS_APP_LIMIT_CPU} CPU limit
Example: cpu: ${GIS_APP_LIMIT_CPU}
${GROUP_TYPE} The group type of the application
Example: storageClassName: appset-storage-class-${GROUP_TYPE}
${NAMESPACE} The namespace of the application
Example: namespace: ${NAMESPACE}
${custom_node_port_*} The external port which is defined by the user, configures in nodePort in Service. After configuring the port, the user can specify the port on UI. The symbol * in the palceholder should be replaced to different names according to the different services.
Example: nodePort: ${custom_node_port_mysql}
Notes:
If you configure namespace in YAML file, do not write in a fixed value, please use the placeholder in the table above.The content below is the YAML of MySQL service:
apiVersion: v1 kind: PersistentVolumeClaim metadata: labels: type: mysql # the name of pvc, ${appsetId} will be replaced when creating the application name: pvc-nfs-mysql-data-${appsetId} spec: # the name of storageClass, the format is appset-storage-class-${GROUP_TYPE}. ${GROUP_TYPE} will be replaced when creating the application storageClassName: appset-storage-class-${GROUP_TYPE} accessModes: - ReadWriteMany resources: requests: storage: 1Gi --- apiVersion: v1 kind: Service metadata: labels: type: mysql name: mysql-server annotations: # The service address, ${SERVICE_IP} and ${NODE_PORT} will be replaced when creating the application addressReg: "jdbc:mysql://${SERVICE_IP}:${NODE_PORT}" # The targetPort of service address is 3306 showPorts: "[3306]" spec: ports: - port: 3307 targetPort: 3306 nodePort: ${custom_node_port_mysql} selector: app: mysql-server type: NodePort --- apiVersion: v1 kind: Service metadata: labels: type: mysql # Use phpMyAdmin service address as the access entrance entrance: "true" # The targetPort of access entrance is 80 entrance-port: "80" name: phpmyadmin spec: ports: - port: 89 targetPort: 80 selector: app: phpmyadmin type: NodePort --- apiVersion: apps/v1 kind: Deployment metadata: labels: app: mysql-server name: mysql-server annotations: # Not support scaling scale: unscalable # The description of MySQL description: MySQL Database # The account information of MySQL accountInfo: "<p>Username/Password:</p><p> supermap/supermap</p><p> root/supermap</p>" # The topological diagram information topoProperty: "{'name':'mysql-server','isPivot':'false','index':1,'parents':[{'name':'phpmyadmin','description':'The UI of database management'}]}" spec: replicas: 1 selector: matchLabels: app: mysql-server template: metadata: labels: app: mysql-server spec: #The image pull secret, ${IMAGE_PULL_SECRET} will be replaced when creating the application imagePullSecrets: - name: "${IMAGE_PULL_SECRET}" containers: - env: - name: MYSQL_DATABASE value: supermap - name: MYSQL_PASSWORD value: supermap - name: MYSQL_ROOT_PASSWORD value: supermap - name: MYSQL_USER value: supermap # ${REGISTRY_URL} will be replaced when creating the application image: ${REGISTRY_URL}supermap/mysql:5.7.12 name: mysql-server # The policy of pulling images, ${IMAGE_PULL_POLICY} will be replaced when creating the application imagePullPolicy: ${IMAGE_PULL_POLICY} # CPU resource limit, ${GIS_APP_LIMIT_CPU} will be replaced when creating the application resources: limits: cpu: ${GIS_APP_LIMIT_CPU} requests: cpu: 300m volumeMounts: - mountPath: /var/lib/mysql name: mysql-volume restartPolicy: Always volumes: - name: mysql-volume persistentVolumeClaim: claimName: pvc-nfs-mysql-data-${appsetId} --- apiVersion: apps/v1 kind: Deployment metadata: labels: app: phpmyadmin name: phpmyadmin annotations: # Not support scaling scale: unscalable # Not support command pad console: noconsole # The description of phpMyAdmin description: The Web client of MySQL # Topological diagram information topoProperty: "{'name':'phpmyadmin','isPivot':'false','index':2,'parents':[]}" # Account information accountInfo: "<p>Username/Password:</p><p> supermap/supermap</p><p> root/supermap</p>" spec: replicas: 1 selector: matchLabels: app: phpmyadmin template: metadata: labels: app: phpmyadmin spec: containers: - env: - name: PMA_HOST value: mysql-server - name: PMA_PORT value: "3307" image: ${REGISTRY_URL}supermap/phpmyadmin:4.6 name: phpmyadmin imagePullPolicy: ${IMAGE_PULL_POLICY} ports: - containerPort: 80 restartPolicy: Always