Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

111 lines (87 sloc) 4.06 KB

Change Configuration

In Knative Serving whenever you change Configuration of the Service, it creates a new Revision which is a point-in-time snapshot of code. It also creates a new Route and the new Revision will start receiving traffic.

Diagram

Change environment variable

To see how Knative reacts to configuration changes, let's change the environment variable the container reads.

Create a service-v2.yaml file that changes TARGET value to C# Sample v2:

apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
  name: helloworld-csharp
  namespace: default
spec:
  runLatest:
    configuration:
      revisionTemplate:
        spec:
          container:
            # Replace `meteatamel` with your actual DockerHub 
            image: docker.io/meteatamel/helloworld-csharp:v1
            env:
              - name: TARGET
                value: "C# Sample v2"

Note that the image is still pointing to v1 version. Apply the change:

kubectl apply -f service-v2.yaml

Now, you should see a new pod and a revision is created for the configuration change:

kubectl get pod,configuration,revision,route 
NAME                                                      READY     STATUS    RESTARTS   
pod/helloworld-csharp-c4pmt-deployment-7fdb5c5dc9-p2hr6   3/3       Running   0          
pod/helloworld-csharp-vkvjt-deployment-7d7d9c9fdd-r27v8   3/3       Running   0          

NAME                                                  configuration.serving.knative.dev/helloworld-csharp   

NAME                                                   
revision.serving.knative.dev/helloworld-csharp-c4pmt   
revision.serving.knative.dev/helloworld-csharp-vkvjt   

NAME                                          
route.serving.knative.dev/helloworld-csharp   

Test that the route is also updated and prints out v2 (replace 1.2.3.4 with IP of Knative ingress):

curl http://helloworld-csharp.default.1.2.3.4.nip.io
Hello World C# v2

Change container image

Configuration changes are not limited to environment variables. For example, a new container image would also trigger a new revision and traffic routed to that revision.

To see this in action, change the Startup.cs to say 'Bye' instead of 'Hello':

await context.Response.WriteAsync($"Bye {target}\n");

Build and push the Docker image tagging with v3. Replace meteatamel with your actual Docker Hub username:

docker build -t meteatamel/helloworld-csharp:v3 .

docker push meteatamel/helloworld-csharp:v3

Once the container image is pushed, create a service-v3.yaml file that changes TARGET value to C# Sample v3 but more importantly, it refers to the new image with tag v3:

apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
  name: helloworld-csharp
  namespace: default
spec:
  runLatest:
    configuration:
      revisionTemplate:
        spec:
          container:
            # Replace meteatamel with your actual DockerHub 
            image: docker.io/meteatamel/helloworld-csharp:v3
            env:
              - name: TARGET
                value: "C# Sample v3"

Apply the change:

kubectl apply -f service-v3.yaml

Test that the route is updated to v3 with the new container. It prints not only v3 (from env variable) but also says Bye (from container). Replace 1.2.3.4 with IP of Knative ingress:

curl http://helloworld-csharp.default.1.2.3.4.nip.io
Bye C# Sample v3

What's Next?

Traffic Splitting

You can’t perform that action at this time.