Session Persistence Considerations

You can configure session persistence when deploying Java EE applications to a WebLogic cluster. You must configure session persistence by updating the weblogic.xml deployment descriptor's session-descriptor element, specifically the persistent-store-type element, whose default value is memory.

To edit the weblogic.xml deployment descriptor's session-descriptor element, see session-descriptor.

For applications deployed to a cluster, use a value suitable for clustered applications, for example, replicated_if_clustered. For information, see Using Sessions and Session Persistence.

For ADF applications, see additional considerations at High Availability Checklist for ADF Applications.

Enabling session affinity or sticky sessions at the ingress controller

To send all client requests of a session to the same Oracle WebLogic Server, you must edit the Kubernetes ingress wls-cluster-ingress and add session affinity annotations.

To ensure session affinity annotations work, we also need to specify a host in the ingress wls-cluster-ingress. You can edit the kubectl to set session affinity.

Run the following command to view the contents of your wls-cluster-ingress file:
kubectl get ingress -n myoke-domain-ns wls-cluster-ingress -o yaml
Sample output:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx-applications
    meta.helm.sh/release-name: ingress-controller
    meta.helm.sh/release-namespace: default
    nginx.ingress.kubernetes.io/configuration-snippet: |
      more_clear_input_headers "WL-Proxy-Client-IP" "WL-Proxy-SSL";
      more_set_input_headers "X-Forwarded-Proto: https";
      more_set_input_headers "WL-Proxy-SSL: true";
  creationTimestamp: "2020-11-30T20:28:48Z"
  generation: 1
  labels:
    app.kubernetes.io/managed-by: Helm
  name: wls-cluster-ingress
  namespace: myoke-domain-ns
  resourceVersion: "2414741"
  selfLink: /apis/extensions/v1beta1/namespaces/myoke-domain-ns/ingresses/wls-cluster-ingress
  uid: f5aa919c-7e93-4ca8-a4ca-ddf791c126dd
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: mydomain-test-cluster-myoke-cluster
          servicePort: 8001
        path: /
status:
  loadBalancer:
    ingress:
    - ip: <public_ip>
Complete the following steps:
  1. Run the following command to enable session affinity:
    kubectl edit ingress -n myoke-domain-ns wls-cluster-ingress
  2. Add the session affinity annotations and the host.

    Note:

    The minimum set of annotations to add is: nginx.ingress.kubernetes.io/affinity

    You can add more annotations to modify the default behavior. For example, you can add nginx.ingress.kubernetes.io/affinity-mode and for maximum stickiness set its value to persistent, or nginx.ingress.kubernetes.io/session-cookie-name to change the default name of the cookie.

    For information about session affinity annotations, see Sticky sessions and Session Affinity.

  3. Save the contents.
  4. Run the following command to view the contents of your wls-cluster-ingress file:
    kubectl get ingress -n myoke-domain-ns wls-cluster-ingress -o yaml
    In the following sample output, the text with comments show the modifications of the ingress. In this case, we enabled session affinity and configured the expiration time for the session cookie:
    [opc@myoke-admin templates]$ kubectl get ingress -n myoke-domain-ns   wls-cluster-ingress -o yaml
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      annotations:
        kubernetes.io/ingress.class: nginx-applications
        meta.helm.sh/release-name: ingress-controller
        meta.helm.sh/release-namespace: default
        nginx.ingress.kubernetes.io/affinity: cookie  # New annotation
        nginx.ingress.kubernetes.io/configuration-snippet: |
          more_clear_input_headers "WL-Proxy-Client-IP" "WL-Proxy-SSL";
          more_set_input_headers "X-Forwarded-Proto: https";
          more_set_input_headers "WL-Proxy-SSL: true";
        nginx.ingress.kubernetes.io/session-cookie-expires: "172800"   #New annotation
        nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"   #New annotation
      creationTimestamp: "2020-11-30T20:28:48Z"
      generation: 2
      labels:
        app.kubernetes.io/managed-by: Helm
      name: wls-cluster-ingress
      namespace: myoke-domain-ns
      resourceVersion: "2419743"
      selfLink: /apis/extensions/v1beta1/namespaces/myoke-domain-ns/ingresses/wls-cluster-ingress
      uid: f5aa919c-7e93-4ca8-a4ca-ddf791c126dd
    spec:
      rules:
      - host: my-server   #New host
        http:
          paths:
          - backend:
              serviceName: mydomain-test-cluster-myoke-cluster
              servicePort: 8001
            path: /
    status:
      loadBalancer:
        ingress:
        - ip: <public_ip>

Note:

If you set the host name in the ingress, you will not be able to access your applications by using the load balancer public IP. To access your applications use the host name you specified in the ingress. That is, you need to add the host name to your DNS servers, or manually map the host name to the public IP of the load balancer. For example, by editing the /etc/hosts file.