Kubernetes - Is it possible to combine Pod.yaml and Service.yaml in one yaml file (but without Deployment)

1/28/2021

I have two different YAMLs one for Pod and one for Service. Is it possible to combine them into one YAML but not to use Deployment kind YAML in which I know we can specify both Pod and Service definition but I do not need to worry about replicas etc. Is it possible to combine them together? I haven't find such example/ guidance in documentation.

Thank you.

-- AndreyS
kubernetes
kubernetes-pod
yaml

3 Answers

1/28/2021

Yes you can put whatever resources you want in a yaml file, you just need to separate them with three dashes e.g:

apiVersion: apps/v1
kind: Service

---
apiVersion: apps/v1
kind: Pod
-- eitann
Source: StackOverflow

1/28/2021

What are you intending to do with this yaml file? 'kubectl create'?

You can separate objects by a line of 3 hyphens: '---'.

-- a guest
Source: StackOverflow

1/28/2021

You can concatenate objects in a single YAML, separating them with ---

Something like:

---
apiVersion: v1
kind: Service
...
---
apiVersion: v1
kind: Pod
...

You may want to create a Deployment first, figuring out what your Pod definition should look like.

Order shouldn't matter, though depending on the client loading it, failure may or may not stop applying the rest of the objects -- kubectl would apply everything it can.

-- SYN
Source: StackOverflow