Hands-On with Services
We're about to get hands-on and put the theory to the test.
We'll augment a simple single-Pod app with a Kubernetes Service. We'll show how to do it in two ways:
- The imperative way (only use in emergencies)
- The declarative way
The Imperative Way
Warning! The imperative way is not the Kubernetes way. It introduces the risk that imperative changes never make back to declarative manifests, rendering the manifests stale. This introduces the risk that stale manifests are used to update the cluster at a later date, unintentionally overwriting important changes that were made imperatively.
Use kubectl
to declaratively deploy the following Deployment (later steps will be done imperatively).
The YAML file is called deploy.yml
and can be found in the services
folder in the book's GitHub repository:
apiVersion: apps/v1 kind: Deployment metadata: name: web-deploy spec: replicas: 10 selector: matchLabels: ...