Creating the Virtual Directory Container

Use the following steps to create the Virtual Directory container.

Procedure

  1. Ensure that the kubectl context is set to the correct environment.
    The mechanism differs based on the Kubernetes environment in use.
  2. Create a key that is used by the Virtual Directory and add the new key to the ConfigMap that contains the configuration for the container.
    For example,
    openssl req -nodes -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365; cat key.pem cert.pem > server.pem
  3. Create a ConfigMap definition file that is named virtualdir-config.yaml.
    This definition file contains the configuration YAML for the container.
    apiVersion: v1 
    kind: ConfigMap 
    metadata: 
      name: virtualdir-config 
      namespace: default 
    data: 
      server.pem: |
        <insert-server.pem-here>
    
      config.yaml: |
        general: 
          ports:
            https: 9636
    
          license:
            key: "add-your-standard-license-key-here"
            accept: standard
    
          admin:
            pwd: passw0rd1
            users:
            - dn: o=sample
              pwd: passw0rd1
              role: Administrator
    
          ssl:
            cert-label: 'server-key'
     
        virtual-dir:
          view:
            suffix: o=view
            attr: cn
          clusters:
          - suffix: o=sample
            endpoint-suffix: o=sample
            servers:
            - target: ldaps://directory.ibm.com:636
              role: Any
              user:
                dn: cn=root
                password: passw0rd1
            attr-mapping:
            - attr: cn
              endpoint-attr: cn
              class: Normal
    
        keyfile:
          keys:
          - label: 'server-key'
            key: "@/var/isvd/config/server.pem"
  4. Create the ConfigMap.
    kubectl create –f virtualdir-config.yaml
  5. Create a deployment file that is named virtualdir-container.yaml.
    This deployment file defines a Virtual Directory container for your environment.
    # 
    # The deployment description of the Verify Directory virtualdir container.
    #
    
    apiVersion: apps/v1
    kind: Deployment
    
    metadata:
      name: isvd-virtualdir
      labels:
        app: isvd-virtualdir
    
    spec:
      selector:
        matchLabels:
          app: isvd-virtualdir
    
      template: 
        metadata:
          labels:
            app: isvd-virtualdir
    
        spec:
          # The name of the service account which has the required
          # capabilities enabled for the isvd container.
          serviceAccountName: isvd
    
          # We use a volume to store the configuration for the 
          # environment.
          volumes:
          - name: config-volume
            configMap:
              name: virtualdir-config
    
          containers:
          - name: isvd-virtualdir
    
            # The fully qualified name of the image.
            image: icr.io/isvd/verify-directory-virtualdir:latest
    
            # The port on which the container will be listening.
            ports:
            - containerPort: 9636
    
            # Environment definition.
            env:
            - name: YAML_CONFIG_FILE
              value: /var/isvd/config/config.yaml  
              
            # The configuration volume.
            volumeMounts:
            - name: config-volume
              mountPath: /var/isvd/config
    
            # The liveness, readiness and startup probes are used by
            # Kubernetes to monitor the health of the container.  Our 
            # health is governed by the health_check.sh script which is
            # provided by the container.
            livenessProbe:
              exec:
                command:
                - /sbin/health_check.sh 
                - livenessProbe
              initialDelaySeconds: 5
              periodSeconds: 10
    
            readinessProbe:
              exec:
                command:
                - /sbin/health_check.sh
              initialDelaySeconds: 5
              periodSeconds: 10 
    
            livenessProbe:
              exec:
                command:
                - /sbin/health_check.sh 
                - startupProbe
              initialDelaySeconds: 5
              periodSeconds: 10
  6. Create the container.
    kubectl create –f virtualdir-container.yaml
  7. You can monitor the bootstrapping of the container by using the logs command.
    kubectl logs -f `kubectl get -o json pods -l app=isvd-virtualdir | jq -r .items[0].metadata.name`
  8. Create a configuration file that is named virtualdir-service.yaml.
    This configuration file defines a service that can be used to access the Virtual Directory. The type of service that is defined differs based on whether the 'load balancer' service type is supported in the environment.
    • If the 'load balancer' service type is not supported in your environment, the following definition can be used.

      # 
      # The service description of the Verify Directory Virtual Directory
      # service.  This is the entry point into the environment and can be
      # accessed over port 30636 from outside of the Kubernetes cluster.
      #
      
      apiVersion: v1
      kind: Service
      
      metadata:
        name: isvd-virtualdir
      
      spec:
        ports:
        - port: 9636
          name: isvd-virtualdir
          protocol: TCP
          nodePort: 30636
      
        selector:
          app: isvd-virtualdir
      
        type: NodePort
    • If the 'load balancer' service type is supported in your environment, the following definition can be used.
      # LoadBalancer service definition....
      apiVersion: v1
      kind: Service
      metadata:
        name: isvd-virtualdir
      spec:
        type: LoadBalancer
        ports:
        - port: 636
        - targetPort: 9636
        selector:
          app: isvd-virtualdir
  9. Create the service.
    kubectl create –f virtualdir-service.yaml
  10. Determine the IP address.
    • If a LoadBalancer service was defined, determine the external IP address of the service, and then use an LDAP client to access the server (port 636).
       kubectl get service isvd-virtualdir --watch
    • If a NodePort service was defined, determine the IP address of the Kubernetes cluster, and then use an LDAP client to access the server (port 30636).
    In a minikube environment, the IP address of the cluster can be obtained with the following command.
    minikube ip
    In an IBM cloud environment, the IP address of the cluster can be obtained with the following command.
    ibmcloud cs workers -c <cluster-name> --json | jq -r .[0].publicIP