Choerodon CLI工具

Choerodon CLI工具主要面向开发人员,支持使用命令行的方式来执行平台中的页面操作。在使用Choerodon的CLI工具前,需要做以下准备。

准备操作

1、下载CLI工具

2、创建client

由于cli工具在访问choerodon平台的时候需要授权,所以采用password类型的oauth2方式去获取 token

需要去choerodon平台的组织下创建客户端,具体设置如下image

.c7n.yaml 配置文件

  1. Contexts:
  2. - Name: staging
  3. Server: http://exapmle.hand-china.com
  4. User:
  5. OrganizationCode: ""
  6. OrganizationId: 0
  7. ProjectCode: ""
  8. ProjectId: 0
  9. Token: ""
  10. UserName: ""
  11. - Name: uat
  12. Server: http://exapmle2.hand-china.com
  13. User:
  14. OrganizationCode: ""
  15. OrganizationId: 0
  16. ProjectCode: ""
  17. ProjectId: 0
  18. Token: ""
  19. UserName: ""
  20. CurrentContext: staging
配置说明是否可选
Contexts []上下文
Contexts [].Name上下文名称必须配置
Contexts [].Server猪齿鱼平台地址必须配置
Contexts [].User操作用户
Contexts [].User.OrganizationCode组织code可选,用户可在命令行中操作回写
Contexts [].User.OrganizationId组织ID可选,用户可在命令行中操作回写
Contexts [].User.ProjectCode项目code可选,用户可在命令行中操作回写
Contexts [].User.ProjectId项目ID可选,用户可在命令行中操作回写
Contexts [].User.Tokenaouth验证token不用配置,用户登录后自动回写
Contexts [].User.UserName用户名不用配置,用户登录后自动回写
CurrentContext当前命令行所处上下文必须配置,与Contexts[].Name对应

登录

使用c7nctl登录之前,必须在用户根目录下创建.c7n.yaml配置文件

  1. ./c7nctl login

-U 用户名 -P 密码 –url 平台gateway地址

登陆完之后,会在用户根目录的回写部分信息,该文件为当前用户的信息,用于后续操作的授权,如果没有登陆然后去操作命令,会提示需要登陆,文件内容为:

  1. OrganizationCode: choerodon-01
  2. OrganizationId: 507
  3. ProjectCode: devops-19-b2
  4. ProjectId: 999
  5. Token: d4d92f34-57bd-4ce0-a7f5-2de31ef92750
  6. UserName: "25147"

image

登出

  1. ./c7nctl logout

登出之后,会清空.c7n.yaml文件,登出之后进行命令操作会提示需要 登陆image

查询用户有权限的组织

  1. ./c7nctl get org

结果如下:

image

修改上下文中用户默认的组织,默认的组织用于后续命令的默认组织

  1. ./c7nctl use org -o xxx

image

查询用户有权限的项目

  1. ./c7nctl get proj

image

修改上下文中用户默认的项目,默认的项目用于后续命令的默认项目

  1. ./c7nctl use proj -p xxx

image

查询运维项目集群

  1. ./c7nctl get cluster -p xxx(-p 非必输)

image

创建运维项目集群

  1. ./c7nctl create cluster --name xxx --code xxx --description xxx -p xxx(-p 非必输)

image

查询集群节点

  1. ./c7nctl get node -c xxx -p xxx(-p 非必输)
  2. -c: 集群code

image

查询项目应用服务

  1. ./c7nctl get app -p xxx(-p 非必输)

image

查询应用服务版本

  1. ./c7nctl get app-version -c xxx -p xxx(-p 非必输)
  2. -c: 应用code

image

创建项目应用服务

  1. ./c7nctl create app --name xxx --code xxx --type xxx --templateAppServiceId xxx --templateAppServiceVersionId xxx(--templateAppServiceId --templateAppServiceVersionId 非必须)

如果要从其他已经存在的应用进行引用,那么需要指定templateAppServiceId和templateAppServiceVersionId

参数解释
env环境code
type应用类型 normal或者test
templateAppServiceId应用id
templateAppServiceVersionId应用发布的版本id

image

查询环境列表

  1. ./c7nctl get env -p xxx(-p 非必输)

image

创建环境

  1. ./c7nctl create env --name xxx --code xxx --cluster xxx --description(非必须) -p xxx(-p 非必输)

image

查询实例列表

  1. ./c7nctl get instance -e xxx -p xxx(-p 非必输)

image

查询实例部署的value列表,并下载到本地

  1. ./c7nctl get value -e xxx -p xxx(-p 非必输)
  2. 保存路径是用户目录下的 c7nctl/value/

imageimage

创建实例

  1. ./c7nctl create instance --env xxx --appServiceId xxx --appServiceVersionId xxx --instanceName xxx --valueFile xxx -p xxx(-p 非必输)
参数解释
env环境code
instanceName实例名称
appServiceId应用ID
appServiceVersionId应用实例版本ID
valueFile部署配置文件,填写绝对路径

查询网络

  1. ./c7nctl get service --env xxx -p xxx(-p 非必输)

image

创建网络

  1. ./c7nctl create service --env xxx --file xxx -p xxx (-p 非必输, file是绝对路径)
  1. ---
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. annotations:
  6. choerodon.io/network-service-instances: spring-test-15ae5+spring-test-d43f5+spring-test-97935+spring-test-1234
  7. choerodon.io/network-service-app: gogo
  8. labels:
  9. choerodon.io/network: service
  10. name: spring-aklfjasdklfjssss
  11. spec:
  12. externalIPs:
  13. - 172.18.2.11
  14. ports:
  15. - name: http1
  16. port: 9999
  17. protocol: TCP
  18. targetPort: 9999
  19. sessionAffinity: None
  20. type: ClusterIP
  21. selector:
  22. app: test
  23. test: app

image

查询域名

  1. ./c7nctl get ingress --env xxxx

image

创建域名

  1. ./c7nctl create ingress --env xxx --file xxx -p xxx (-p 非必输, file是绝对路径)
  1. apiVersion: extensions/v1beta1
  2. kind: Ingress
  3. metadata:
  4. annotations: {}
  5. labels:
  6. choerodon.io/network: ingress
  7. name: c7ncli-test
  8. spec:
  9. rules:
  10. - host: 2223.c7nctl-test.com
  11. http:
  12. paths:
  13. - backend:
  14. serviceName: test-test
  15. servicePort: 4321
  16. path: /
  17. tls:
  18. - hosts:
  19. - 2223.c7nctl-test.com
  20. secretName: asdf

image

查询证书

  1. ./c7nctl get cert --env xxxx -p xxx(-p 非必输)

image

创建证书

  1. ./c7nctl create cert --env xxx --file xxx -p xxx (-p 非必输, file是绝对路径)
  1. ---
  2. apiVersion: certmanager.k8s.io/v1alpha1
  3. kind: Certificate
  4. metadata:
  5. name: c7nctl-cli-test
  6. namespace: staging-test
  7. spec:
  8. commonName: 1.c7nctl-test.com
  9. dnsNames:
  10. - 2.c7nctl-test.com
  11. - 3.c7nctl-test.com
  12. - 4.c7nctl-test.com
  13. existCert:
  14. cert: |
  15. -----BEGIN CERTIFICATE-----
  16. MIICYTCCAcoCCQCs45mePIbzRTANBgkqhkiG9w0BAQUFADB1MQswCQYDVQQGEwJV
  17. UzENMAsGA1UECAwETWFyczETMBEGA1UEBwwKaVRyYW5zd2FycDETMBEGA1UECgwK
  18. aVRyYW5zd2FycDETMBEGA1UECwwKaVRyYW5zd2FycDEYMBYGA1UEAwwPd3d3LjU5
  19. MXdpZmkuY29tMB4XDTE4MTAxNzAyMTA0OFoXDTI4MTAxNDAyMTA0OFowdTELMAkG
  20. A1UEBhMCVVMxDTALBgNVBAgMBE1hcnMxEzARBgNVBAcMCmlUcmFuc3dhcnAxEzAR
  21. BgNVBAoMCmlUcmFuc3dhcnAxEzARBgNVBAsMCmlUcmFuc3dhcnAxGDAWBgNVBAMM
  22. D3d3dy41OTF3aWZpLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAtxtP
  23. cxgppTHrbzWloh26fXfIyLZI+YpNMCnJ+4wcv3jnZZ6OZsvnoo0z/yl/A9kDY9r5
  24. Rft9fwE4WKMSPNKlGd4psPLw1XNHAXhi8RAy1cHgkBMuwor6ZJhFgnsqKk4Xp68D
  25. jaCI2oxu2SYIBU67Fxy+h7G5BsWKwARtj5kP8NECAwEAATANBgkqhkiG9w0BAQUF
  26. AAOBgQC2Pko8q1NicJ0oPuhFTPm7n03LtPhCaV/aDf3mqtGxraYifg8iFTxVyZ1c
  27. ol0eEJFsibrQrPEwdSuSVqzwif5Tab9dV92PPFm+Sq0D1Uc0xI4ziXQ+a55K9wrV
  28. TKXxS48TOpnTA8fVFNkUkFNB54Lhh9AwKsx123kJmyaWccbt9Q==
  29. -----END CERTIFICATE-----
  30. key: |
  31. -----BEGIN RSA PRIVATE KEY-----
  32. MIICXgIBAAKBgQC3G09zGCmlMetvNaWiHbp9d8jItkj5ik0wKcn7jBy/eOdlno5m
  33. y+eijTP/KX8D2QNj2vlF+31/AThYoxI80qUZ3imw8vDVc0cBeGLxEDLVweCQEy7C
  34. ivpkmEWCeyoqThenrwONoIjajG7ZJggFTrsXHL6HsbkGxYrABG2PmQ/w0QIDAQAB
  35. AoGBAIxvTcggSBCC8OciZh6oXlfMfxoxdFavU/QUmO1s0L+pow+1Q9JjoQxy7+ZL
  36. lTcGQitbzsN11xKJhQW2TE6J4EVimJZQSAE4DDmYpMOrkjnBQhkUlaZkkukvDSRS
  37. JqwBI/04G7se+RouHyXjRS9U76HnPM8+/IS2h+T6CbXLOpYBAkEA2j0JmyGVs+WV
  38. I9sG5glamJqTBa4CfTORrdFW4EULoGkUc24ZFFqn9W4e5yfl/pCkPptCenvIrAWp
  39. /ymnHeLn6QJBANbKGO9uBizAt4+o+kHYdANcbU/Cs3PLj8yOOtjkuMbH4tPNQmB6
  40. /u3npiVk7/Txfkg0BjRzDDZib109eKbvGKkCQBgMneBghRS7+gFng40Z/sfOUOFR
  41. WajeY/FZnk88jJlyuvQ1b8IUc2nSZslmViwFWHQlu9+vgF+kiCU8O9RJSvECQQCl
  42. Vkx7giYerPqgC2MY7JXhQHSkwSuCJ2A6BgImk2npGlTw1UATJJq4Z2jtwBU2Z+7d
  43. ha6BEU6FTqCLFZaaadKBAkEAxko4hrgBsX9BKpFJE3aUIUcMTJfJQdiAhq0k4DV8
  44. 5GVrcp8zl6mUTPZDaOmDhuAjGdAQJqj0Xo0PZ0fOZPtR+w==
  45. -----END RSA PRIVATE KEY-----

image

查找配置映射

  1. ./c7nctl get cm --env xxx -p xxx(-p 非必输)

image

创建配置映射

  1. ./c7nctl create cm --env xxx --file xxx -p xxx (-p 非必输, file是绝对路径)
  1. apiVersion: v1
  2. data:
  3. key: value
  4. kind: ConfigMap
  5. metadata:
  6. name: c7nctl-cli-test2

image

查询密文

  1. ./c7nctl get secret --env xxxx -p xxx(-p 非必输)

image

创建密文

  1. ./c7nctl create secret --env xxx --file xxx -p xxx (-p 非必输, file是绝对路径)

apiVersion: v1kind: Secretmetadata:name: secret-c7n-ctlstringData:key1: value1key2: value2

  1. apiVersion: v1
  2. kind: Secret
  3. metadata:
  4. name: secret-c7n-ctl
  5. stringData:
  6. key1: value1
  7. key2: value2

image

查询自定义资源

  1. ./c7nctl get custom --env xxxx -p xxx(-p 非必输)

image

创建自定义资源

  1. ./c7nctl create custom --env xxx --file xxx -p xxx (-p 非必输, file是绝对路径)
  1. apiVersion: v1
  2. kind: PersistentVolume
  3. metadata:
  4. name: pv-12-18-023
  5. spec:
  6. accessModes:
  7. - ReadWriteMany
  8. capacity:
  9. storage: 1Gi
  10. nfs:
  11. path: /u01/staging
  12. server: 192.168.16.215

image

查询PV

  1. ./c7nctl get pv

image

创建PV

  1. ./c7nctl ceate pv --clusterCode xxx --file xxx
  1. apiVersion: v1
  2. kind: PersistentVolume
  3. metadata:
  4. name: pv-12-18-023
  5. spec:
  6. accessModes:
  7. - ReadWriteMany
  8. capacity:
  9. storage: 1Gi
  10. nfs:
  11. path: /u01/staging
  12. server: 192.168.16.215

查询PVC

  1. ./c7nctl get pvc --env xxx

image

创建PVC

  1. ./c7nctl create pvc --clusterCode xxx -envCode xxx --file xxx (file是绝对路径)
  1. apiVersion: v1
  2. kind: PersistentVolumeClaim
  3. metadata:
  4. name: pvc-12-18-111
  5. spec:
  6. accessModes:
  7. - ReadWriteMany
  8. volumeName: pv-12-18-05
  9. resources:
  10. requests:
  11. storage: 1Gi