Creating a Kubernetes Service

Kubernetes services are used to expose Control Center Monitor application running inside the cluster as a network service. It also provides load balancing between different instances running inside a cluster.

Refer to the sample service file given below and modify the following parameters:
  • Ports

    Exposed and target port should match

  • app (Selector label name)

    Should match the satefulset name

  • External IPs

    A public IP used to access the application

Sample Service File
apiVersion: v1
kind: Service
metadata:
  name: cc-service
  labels:
    app: cc-app
spec:
  selector:
    app: cc-app
  type: LoadBalancer/NodePort
  externalTrafficPolicy: Local 
  ports:
  - name: cc-swing-console
    port: 58080
    targetPort: 58080
  - name: cc-swing-console-secure
    port: 58081
    targetPort: 58081
  - name: cc-web-console
    port: 58082
    targetPort: 58082
  - name: cc-web-console-secure
    port: 58083
    targetPort: 58083
  sessionAffinity: ClientIP
# Replace with your IP if want to use it, otherwise can remove this tag
  externalIPs:
  - 111.22.333.444
To create a Kubernetes service, follow the steps given below:
  1. Save the sample service file as cc-service.yaml inside Kubernetes_scripts.
  2. Invoke the following commands:
    $ cd
    $ cd Kubernetes_scripts
    $ vi cc-service.yaml
  3. Copy sample contents from the sample service file into this file and save it.
    $ kubectl create -f cc-service.yaml
  4. Invoke the following command to verify if the service was created:
    $ kubectl get svc