<p>Just finished reading Nigel Poulton's <strong>The Kubernetes Book</strong>, but I am somewhat puzzled with Services. </p>

<p>Could a Service be added to the Deployment manifest below somehow?Or does the Service have to be POSTed on its own? Isn't the whole purpose of a deployment to specify everything needed for the app to run?</p>

<pre><code>apiVersion: apps/v1beta2
kind: Deployment
metadata: 
  name: hello-deploy
spec:
  replicas: 10
  selector:
    matchLabels:
      app: hello-world
  minReadySeconds: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-pod
        image: nigelpoulton/k8sbook : latest
        ports:
        - containerPort: 8080
</code></pre>

Kermit
<p>They're different objects and you have to submit them separately (HTTP POST, <code>kubectl apply</code>, ...).</p>

<p>There are a couple of tricks you can do to minimize the impact of this:</p>

<ul>
<li><p>You can use a <a href="https://kubernetes.io/docs/concepts/cluster-administration/manage-deployment/#organizing-resource-configurations" rel="noreferrer">multi-document YAML file</a> and submit that as a single thing, like</p>

<pre><code>---
apiVersion: apps/v1
kind: Deployment
...
---
apiVersion: v1
kind: Service
...
</code></pre></li>
<li><p>There is an undocumented <a href="https://github.com/kubernetes/kubernetes/blob/master/hack/testdata/list.yaml" rel="noreferrer"><code>kind: List</code></a> that could embed multiple objects</p>

<pre><code>apiVersion: v1
kind: List
items:
  - apiVersion: apps/v1
    kind: Deployment
    ...
  - apiVersion: v1
    kind: Service
    ...
</code></pre></li>
<li><p>You can use a higher-level deployment manager such as <a href="https://helm.sh/" rel="noreferrer">Helm</a> that lets you keep each object in a separate file, but deploy them in a single command.</p></li>
</ul>

<p>It's perhaps unfortunate that a couple of Kubernetes objects have names that are different from their plain English meanings (a Deployment doesn't cover all of the steps or parts of deploying a whole application; a Service is just an IP/DNS pointer and not a service implementation) but that's the way it is.  I tend to capitalize the Kubernetes object names when it will disambiguate things.</p>
