Managed services Kubernetes resource controller for services

The Managed services Kubernetes custom resource definition and controller provides you with the ability to deploy and delete Managed services service instances using Kubernetes yaml resource files. With this capability, a single Kubernetes yaml can be created to deploy a composite application that consists of both Kubernetes deployable resources and traditional infrastructure resources, which are deployed with Terraform in Managed services. A typical containerized application is an example of a Kubernetes deployable resource. Examples of traditional infrastructure resources are virtual machines, storage, and so on.

About the task

The Managed services Kubernetes resource controller deploys the Managed services service and waits for Active status. If the deployment Fails, then the controller continues to issue Resume requests until the service becomes Active.

Before you begin

A role binding must be defined for a user or group to have the authority to deploy a service in Managed services.

The following is an example for the icp:camgroup:operator user group:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
   name: icp:camgroup:operator:service
roleRef:
   apiGroup: rbac.authorization.k8s.io 
   kind: ClusterRole  
   name: cam-controller-manager-role
subjects:
- apiGroup: rbac.authorization.k8s.io  
   kind: Group  
   name: icp:camgroup:operator

Procedure

Deploying a Managed services service

  1. Go to your Kubernetes environment that is the same as Managed services.

  2. Create your YAML file. The file allows the definition of the service deployment to be placed under the source control, which allows changes to be tracked. An example Managed services Kubernetes service resource controller yaml file is:

     apiVersion: cloudautomationmgr.ibm.com/v1alpha1
     kind: Service
     metadata:
       name: service-test-vsphere-1    
       namespace: "default"
     spec:    ​
       connection: "camDc2Rtp"
       service:
         name: "LrhNodeOnSingleVM-vsphere"       //Instance that you are going to deploy
         instance_plan: "host-164"             
         action: "Provision"                    //The action is provision. 
         parameters:
           templateParameters: []
           specifications:
             parameters:                       //The parameters that are passed with the instance
               vSphereConfig: vSphere-CAMDC2
               vm_ipv4_address: "9.9.9.9"
               vm_name: "camc-vis232c-vm-164"
               vm_dns_servers: 
               - "9.9.9.9"
               vm_dns_suffixes: ["rtp.raleigh.ibm.com"]
    
    • parameters - It is a collection of name-value pairs that map to the Managed services Service Input Parameter Key and Value. For example:

      parameters: 
        vSphereConfig: vSphere-CAMDC2
        vm_ipv4_address: "9.9.9.9"
        vm_dns_suffixes: ["rtp.raleigh.ibm.com"]
      
    • secretParameters - (Optional) List of Managed services secret parameter data objects to use with the deployed service. For example:

      secretParameters: 
      	name: vm_password_lrh 
      	secretKeyRef: 
      		name: vm-password-lrh-secret 
      		key: password
      

      where

      name: name of service parameter

      secretKeyRef:

      name: Name of the Kubernetes secret

      key: key is the name of the secret data defined in the secret

  3. Run the following kubectl command to deploy a Managed services service:

    kubectl apply -f <yaml file name>
    

Displaying the status of a Managed services service

  1. Verify the status of a deployed Managed services service by using either of the following commands:

    kubectl describe -f <yaml file name>
    

    or

    kubectl describe services.cloudautomationmgr.ibm.com service-test-vsphere-1 -n default
    

    Example:

     Name:         service-test-vsphere-1
     Namespace:    default
     Labels:       <none>
     Annotations:  kubectl.kubernetes.io/last-applied-configuration:
                     {"apiVersion":"cloudautomationmgr.ibm.com/v1alpha1","kind":"Service","metadata":{"annotations":{},"name":"service-test-vsphere-1","namespa...
     API Version:  cloudautomationmgr.ibm.com/v1alpha1
     Kind:         Service
     Metadata:
       Creation Timestamp:  2019-08-09T19:50:52Z
       Finalizers:
         Service.cloudautomationmgr.ibm.com
       Generation:        2
       Resource Version:  6549804
       Self Link:         /apis/cloudautomationmgr.ibm.com/v1alpha1/namespaces/default/services/service-test-vsphere-1
       UID:               feadd3c9-bade-11e9-a019-00163e01cbab
     Spec:
       Secrets:
         Env:
       Service:
         Action:         Provision
         instance_plan:  Standard
         Name:           LrhNodeOnSingleVM-vsphere
         Parameters:
           Specifications:
             Parameters:
               V Sphere Config:  vSphere-CAMDC2
               vm_datacenter:    CAMDC2
               vm_dns_servers:
                 9.42.106.3
               vm_dns_suffixes:
                 rtp.raleigh.ibm.com
               vm_ipv4_address:  9.46.126.166
               vm_name:          camc-vis232c-vm-166
     Status:
       Action:  provision
       Conditions:
         Last Transition Time:  2019-08-09T19:53:43Z
         Reason:                Active
         Status:                True
         Type:                  provision
       Message:
       Service ID:              5d4dce9d5b972d001dc804d8
       Status:                  Active
     Events:
       Type    Reason                 Age    From                    Message
       ----    ------                 ----   ----                    -------
       Normal  provision:Submitted    2m51s  cam-controller-service  provision status changed for default/service-test-vsphere-1
       Normal  provision:In Progress  2m32s  cam-controller-service  provision status changed for default/service-test-vsphere-1
       Normal  provision:Active       1s     cam-controller-service  provision status changed for default/service-test-vsphere-1
    
    
    • The Status fields returned from the kubectl describe command:

      • Action - Last action performed, that is provision, resume, delete
      • Message - Last error message, blank if no error message.
      • Service ID - Managed services service ID of the deployment.
      • Status - Status of the last action performed.
      • Conditions
        • Last Transition Time - Last update time of the condition.
        • Reason - The status of the Managed services action.
        • Status - It is 'True' when the condition is valid.
        • Type - The type of the condition - the Managed services action (For example, provision, resume, delete).
      • Outputs
        • Name - Name of the output parameter.
        • Type - The type of the parameter, that is, string, list, map.
        • Value - The value of the output parameter in JSON format.
    • The Event fields returned from the kubectl describe command are Type, Reason, Age, and From. Example:

      Type    Reason                 Age    From                    Message
      ----    ------                 ----   ----                    -------
      Normal  provision:Submitted    6m53s  cam-controller-service  provision status changed for default/service-test-vsphere-1
      Normal  provision:In Progress  6m34s  cam-controller-service  provision status changed for default/service-test-vsphere-1
      Normal  provision:Active       4m3s   cam-controller-service  provision status changed for default/service-test-vsphere-1
      
  2. Optionally, you can also use Managed services Kubernetes controller startup parameters - controller parameter. They are defined in cam-controller-statefulset.yaml file. The args parameters are specified in the pod definition.

    The -syncPeriod is a controller parameter for the time duration between resource status checks. Value units are 's', 'm', 'h'." (Default is 2m).

    For example:

    • -syncPeriod=2h30m
    • -syncPeriod=300s
    • -syncPeriod=30m

Deleting a deployed Managed services service

If you no longer require the deployed instance of a service instance, run either of the following commands to delete it:

kubectl delete -f <yaml file name>

or

kubectl delete services.cloudautomationmgr.ibm.com service-test-vsphere-1 -n default

Note: The command deletes the Managed services instance. After the Managed services instance is successfully deleted, the Kubernetes resource that represents the Managed services instance is also deleted.