Service
Learn how to create a Kubernetes service and how service discovery works.
Deployment
Service
Service YAML
# Under the helloworld-springboot-tomcat directory , create a k8s directory
mkdir k8s/
kubectl create service clusterip helloworld \
--tcp=8080:8080 \
--dry-run \
-o yaml > k8s/service.yaml# API Version and Kind are important to indicate the type of resource
apiVersion: v1
kind: Service
metadata:
# Every Kubernetes resource has a name that's unique within a namespace
name: helloworld
# Every Kubernetes can have labels, label key/value pairs can be queried later.
labels:
app: helloworld
spec:
# The type of the service - this one is an internal only service
type: ClusterIP
# Any Pods that matches these labels will be load balanced through
# this Service (L4 load balancer)
selector:
app: helloworld
ports:
# A port can have a name, it can be renamed to be more descriptive
# such as "http", "jmx", "metrics", etc.
- name: 8080-8080
# The port to listen on by the Service (L4 Load Balancer)
port: 8080
# The port to forward traffic to on the destination Pod
targetPort: 8080
# TCP or UDP protocol
protocol: TCPDeploy
Service Discovery
Endpoints
DNS Name
Last updated
Was this helpful?