2. Introduction the K8 YAML Files
We saw in the overview how to install kubetctl and minikube, and how to pull an image create a POD, and expose it to the outside world. Here we will expand on this to create another K8 object called a deployment.
K8 Objects via YAML file
PODs
Create a new folder called k8_echoserver
Create a file called echoserver_pod.yaml
Add the followings elements to the file
apiVersion: v1
kind: Pod
metadata:
name: yml-echoserver
spec:
containers:
- name: yml-es
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_pod.yaml
You should see a message that the POD has been created.
A single POD like this has no real purpose, it would normally be created to accompany other PODs.
Visit the minikube dashboard, and look at the PODs, you will see the POD is there, but there is no Deployment or Service for it. In actual fact, you can’t create a Deployment from a running POD, therefore you can’t expose it as a service either.
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
name
- a unique name within the namespaceimage
- the container image that will be used to construct the PODs
To remove the resources that have been created type
kubectl delete -f echoserver_pod.yaml
Your Task
Use the steps from above and create a POD for the stream2stream/pingme image. It can be pulled from docker.io.