2. Modify/add the spec/template/spec/containers/ports node and add the following content
- containerPort: 8080 protocol: TCP
3. Add the yaml file of the service, usually named as xxxx-srv.yaml, where xxxx is the service name. The content is as follows:
apiVersion: v1 kind: Service metadata: name: service name namespace: default labels: k8s-app: service name (this needs to be consistent with the k8s-app field named in the xxxx-rc.yaml file) kubernetes.io/name: "service name" spec: type: NodePort selector: k8s-app: service name ports: - name: service name-sv port: 8081 (the port on the pod) targetPort: 8081 (the port on the service) nodePort: 30964 (port on node, if not set it will be automatically assigned by kubernets)
4. Create a service
kubectl create -f xxxx-svc.yaml
5. View the service port number, where NodePort is the port number exposed by the service to the outside world
kubectl describe service xxxx-service
6. Edit /opt/haproxy/config/haproxy.cfg to add haproxy configuration.
listen servicename bind local ip: the address open to the outside world mode tcp server server1 service address: service port number check port service port number inter 2000 rise 2 fall 2