3. Deployments with a YAML File
We learned earlier that PODs without a Deployment object cannot be exposed as Services. In this section we will construct a YAML file that describes the Deployment and Service of the echoserver
K8 Objects via YAML file
Deployments
If you haven’t already created the k8_echoserver
folder create a new folder called k8_echoserver
. Navigate into the k8_echoserver folder.
Create a file called echoserver_deployment.yaml
Add the followings elements to the file
apiVersion: apps/v1
kind: Deployment
metadata:
name: yml-echoserver-deployment
namespace: default
spec:
replicas: 1
selector:
matchLabels:
service_id: echo-sever-from-yml
template:
metadata:
labels:
service_id: echo-sever-from-yml
spec:
containers:
- name: yml-echo-server
image: k8s.gcr.io/echoserver:1.4
Creating resources from the yaml file
Once you have created the file, from the shell where the file is located execute the command
kubectl apply -f echoserver_deployment.yaml
You should see a message that the Deployment has been created.
Visit the minikube dashboard, and look at the PODs, Deployments and Services, you will see the POD and the Deployment are there, but no service.
YAML Content Description
apiVersion
- identifies the version of the schema the object should have
kind
- a string that identifies the schema this object should have. Type kubectl api-resources
to see the possible options.
metadata
- Information that uniquely identifies the object
metadata.name
- uniquely identifies this object within the current namespace
metadata.namespace
- if not specified defaults to default
spec
- What state do you desire for the object, in our example above we want it to have a
spec.replicas
- target number of PODsspec.selector.matchLabels
- searches for a matchingspec.template.metadata.labels
value to determine which POD specification should be created
To remove the resources that have been created type
kubectl delete -f echoserver_deployment.yaml
Your Task
Use the steps from above and create a Deployment for the stream2stream/pingme image. It can be pulled from docker.io.