Contents

Skaffold - Profiles

 Skaffold Profiles are found within the skaffold.yaml file and allow you choose which applications to deploy based on a set of conditions, such as environments or clusters.

Introduction

In my previous post we generated a starting point for developing applications in this post we will dive deeper into skaffolds profiles.

Quick Start

 Cookiecutter is a tool that automates project generation.

We will be starting from where we finished last post, please generate the required code

  1. Install cookiecutter

    1
    
    pip3 install cookiecutter
    
  2. Generate template

    1
    
    cookiecutter https://github.com/mmcloud/cookiecutter-skaffold-init --checkout v1.0.0
    

    If you would prefer to skip to the end and read through

    1
    
    cookiecutter https://github.com/mmcloud/cookiecutter-skaffold-init --checkout v2.0.0
    
  3. Change directory to generated folder (demo directory is default, change according to inputted project slug)

    1
    
    cd demo
    
  4. Start Minikube

    1
    
    minikube start
    
  5. Develop using skaffold or use cloudcode plugin

    1
    
    skaffold dev
    
  6. Create endpoint

    1
    
    minikube service --url hostservice-external
    

 Changing Source Code will automatically rebuild image

Tutorial

We start with the following yaml. There are 2 stages, build and deploy.

In the build stage we are building the host service from the src directory.
In the deploy stage we are using the newly built image from the above and deploying it.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
apiVersion: skaffold/v1beta2
kind: Config
build:
  artifacts:
  - image: hostservice
    context: src/hostservice
deploy:
  kubectl:
    manifests:
    - ./kubernetes-manifests/hostservice.yaml  

Profiles

Profiles can be used for fine tuning deployment to different environments. We will make a profile for minikube as it is our development environment, you can extend the pattern for other clusters.

  1. Get context of cluster

    1
    
    kubectl config current-context
    
  2. Update skaffold.yaml with a new profile

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    
    apiVersion: skaffold/v1beta2
    kind: Config
    build:
      artifacts:
      - image: hostservice 
        context: src/hostservice
    deploy:
      kubectl:
        manifests:
        - ./kubernetes-manifests/hostservice.yaml
    profiles:
    - name: development
      activation:
        - kubeContext: minikube
          command: dev
    

Lets assume we want to have additional dns tools only in development for debugging.

  1. Create dnsutils.yaml file

    1
    
    touch ./kubernetes-manifests/dnsutils.yaml
    
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    
    apiVersion: v1
    kind: Pod
    metadata:
      name: dnsutils
      namespace: default
    spec:
      containers:
      - name: dnsutils
        image: k8s.gcr.io/e2e-test-images/jessie-dnsutils:1.3
        command:
          - sleep
          - "3600"
        imagePullPolicy: IfNotPresent
      restartPolicy: Always
    
  2. Reference manifests in development profile

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    
    apiVersion: skaffold/v1beta2
    kind: Config
    build:
      artifacts:
      - image: hostservice 
        context: src/hostservice
    deploy:
      kubectl:
        manifests:
        - ./kubernetes-manifests/hostservice.yaml
    profiles:
    - name: development
      activation:
        - kubeContext: minikube
          command: dev
      deploy:
        kubectl:
          manifests:
          - ./kubernetes-manifests/dnsutils.yaml
    
  3. Run skaffold

    1
    
    skaffold dev
    

 Profiles here are additive, everything above the profile is still deployed and then the dns is added as extra in the context of minikube