Home Explore Blog CI



docker

2nd chunk of `content/guides/kube-deploy.md`
5d85e66f38415e04e9ed41ed363c849107ec3370774fe4af00000001000008f6
You already wrote a basic Kubernetes YAML file in the Orchestration overview part of this tutorial. Now, you can write a slightly more sophisticated YAML file to run and manage your Todo app, the container `getting-started` image created in [Part 2](02_our_app.md) of the Quickstart tutorial. Place the following in a file called `bb.yaml`:

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: bb-demo
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      bb: web
  template:
    metadata:
      labels:
        bb: web
    spec:
      containers:
        - name: bb-site
          image: getting-started
          imagePullPolicy: Never
---
apiVersion: v1
kind: Service
metadata:
  name: bb-entrypoint
  namespace: default
spec:
  type: NodePort
  selector:
    bb: web
  ports:
    - port: 3000
      targetPort: 3000
      nodePort: 30001
```

In this Kubernetes YAML file, there are two objects, separated by the `---`:

- A `Deployment`, describing a scalable group of identical pods. In this case, you'll get just one `replica`, or copy of your pod, and that pod (which is described under the `template:` key) has just one container in it, based off of your `getting-started` image from the previous step in this tutorial.
- A `NodePort` service, which will route traffic from port 30001 on your host to port 3000 inside the pods it routes to, allowing you to reach your Todo app from the network.

Also, notice that while Kubernetes YAML can appear long and complicated at first, it almost always follows the same pattern:

- The `apiVersion`, which indicates the Kubernetes API that parses this object
- The `kind` indicating what sort of object this is
- Some `metadata` applying things like names to your objects
- The `spec` specifying all the parameters and configurations of your object.

## Deploy and check your application

1. In a terminal, navigate to where you created `bb.yaml` and deploy your application to Kubernetes:

   ```console
   $ kubectl apply -f bb.yaml
   ```

   You should see output that looks like the following, indicating your Kubernetes objects were created successfully:

   ```shell
   deployment.apps/bb-demo created
   service/bb-entrypoint created
   ```

2. Make sure everything worked by listing your deployments:

Title: YAML File Details and Deployment Instructions
Summary
This section elaborates on the `bb.yaml` file, explaining its two key components: a Deployment (for managing pods) and a NodePort service (for routing external traffic to the pods). It also highlights the common structure of Kubernetes YAML files: `apiVersion`, `kind`, `metadata`, and `spec`. The section then provides instructions to deploy the application using `kubectl apply -f bb.yaml` and verifies the successful creation of the deployment and service.