Software Engineering

How to Deploy a Docker Container to Kubernetes

Once you have a Docker container, it is really simple to deploy it to Kubernetes.

Generate a Deployment YAML

kubectl provides a fantastic way to help generate deployment yamls.

kubectl create deployment <app_name> --image=<some/image> --dry-run=client -o yaml > <deployment_file_name>.yaml

Perform the Deployment

Now that we have a deployment yaml, we can simply run:

kubectl apply -f <deployment_file_name>.yaml

What next?

Next you might want to add a Service so that the deployment is available to the world.

Open up the deployment yaml file generated and add the following:

apiVersion: v1
kind: Service
  name: lb-service
    app: lb-service
  type: LoadBalancer
  - port: 80
     targetPort: 5000
    app: <app_name>

Note that the above Service uses a LoadBalancer type, listens for requests on port 80, forwards them onto port 5000 to the app specified in the selector label.

We called this <app_name> above, which you should swap out with whatever appname you chose before. This is specified by the label used in the original yaml.