Deploying a service for a pod consists of two resources: a service to describe the service to be provided, and a workload to describe the pods which will fulfill the service. The most common kind of workload is a deployment. You can create services and deployments by authoring Kubernetes manifests.
Services
Services must provide a selector to describe which pods will fulfill this service's requests. If your service exposes any ports, they will also be described here.
Code Block |
---|
apiVersion: v1 kind: Service metadata: # Labels for a service do not need to match its pods, but can overlap. labels: app.kubernetes.io/name: example app.kubernetes.io/component: web name: example-web namespace: default spec: # Ports describe how the port will be exposed within the cluster as well as # the port on a pod to which traffic will be routed. If your service doesn't # expose any ports, this section is not required. ports: - name: http port: 3000 protocol: TCP targetPort: http # The selector contains labels which must match for a pod to be considered # part of this service. These labels will usually be part of the metadata # section of your pod template in a deployment spec. selector: app.kubernetes.io/name: example app.kubernetes.io/component: web # If your service doesn't expose ports, you can use None here instead. type: ClusterIP |
Deployments
Deployments describe how to create the pods that will run to fulfill a service.
...