New Project

If you already a project with an existing Dockerfile, you can use that. If you do not, kubes generates a starter Dockerfile that runs nginx. For this tutorial, we’ll start with an empty folder.

mkdir demo
cd demo

For this tutorial, here are examples of AWS ECR and Google GCR repos, though any repo will work.

AWS:

REPO=$(aws ecr describe-repositories --repository-name demo | jq -r '.repositories[].repositoryUri')

Google:

export GOOGLE_PROJECT=project-123
REPO=gcr.io/$GOOGLE_PROJECT/demo

Let’s initialize a starter kubes project. This is similar to a git init.

$ kubes init --app demo --repo $REPO
      create  Dockerfile
      create  .kubes/config.rb
      create  .kubes/config/env/dev.rb
      create  .kubes/config/env/prod.rb
      create  .kubes/resources/base/all.yaml
      create  .kubes/resources/base/deployment.yaml
      create  .kubes/resources/shared/namespace.yaml
      create  .kubes/resources/web/deployment.yaml
      create  .kubes/resources/web/deployment/dev.yaml
      create  .kubes/resources/web/deployment/prod.yaml
      create  .kubes/resources/web/service.yaml
Initialized .kubes folder
Updated .gitignore
$

To learn more about the generated structure, here are the Structure Docs.

Let’s explore some of the generated files.

Config

The config.rb is where you can configure Kubes settings.

.kubes/config.rb

Kubes.configure do |config|
  config.repo = "112233445566.dkr.ecr.us-west-2.amazonaws.com/demo" # may be gcr.io/project-123/demo
  config.logger.level = "info"
  # auto-switching
  # config.kubectl.context = "dev-cluster"
end

This is where the --repo from kubes init got saved. The other options are covered in the Env Config Docs.

Dockerfile

The Dockerfile is a simple starter example that just runs nginx

Dockerfile:

# Simple example starter
FROM nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Note: If your project already has a Dockerfile, kubes will use that instead of generating a starter one.

Next, we’ll review the resources.