🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Knative Tutorials: Deploying HTTP Workloads using Knative Serving


DOCKER CODE LINK – https://github.com/KubernetesSchool/Knative-Resources/tree/main/docker


Deploying HTTP Workloads using Knative Serving

1.1 Creating Knative Services

Create a new file called knative-service.yaml

Paste in the following text:

apiVersion: serving.knative.dev/v1 
kind: Service
metadata:
  name: serving-app 
  namespace: default 
spec:
  template:
    spec:
      containers:
        - image: bsucaciu/knative-serving:v1

Deploy Knative Service

kubectl apply -f knative-service.yaml

Check if the service has been deployed

kubectl get ksvc

1.2 Access the newly created Knative Service

Add a new entry to hosts file

Unix: /etc/hosts
Windows: C:\Windows\System32\drivers\etc\hosts

Entry value

127.0.0.1       serving-app.default.example.com

Open your preferred web browser and navigate to:

http://serving-app.default.example.com

2.1 Scalling to zero

Default Global Config

kubectl describe configmap config-autoscaler -n serving
apiVersion: v1
kind: ConfigMap
metadata:
 name: config-autoscaler
 namespace: serving
data:
 enable-scale-to-zero: "true"
 scale-to-zero-grace-period: "30s"
 scale-to-zero-pod-retention-period: "0s"
 container-concurrency-target-default: "100"
 container-concurrency-target-percentage: "0.7"
 max-scale-up-rate: "1000"
 max-scale-down-rate: "2"
 panic-window-percentage: "10"
 panic-threshold-percentage: "200"
 stable-window: "60s"
 target-burst-capacity: "200"
 requests-per-second-target-default: "200"

Check the number of running pods

kubectl get pods

Apply the new configuration

kubectl apply -f config-autoscaler.yaml

3.1 Managing revisions

Inspect current revision(s)

kubectl get revision

Edit the knative-service.yaml file by appending the following configuration

          env:
            - name: MESSAGE
              value: Hello

Apply the updated Knative Service

kubectl apply -f knative-service.yaml

Inspect current revisions

kubectl get revision

Change the image version

        - image: bsucaciu/knative-serving:v2

Inspect current revisions

kubectl get revision

3.3 Working with Subroutes

Display current route configuration

kubectl get routes 

Split traffic accross revisions

  traffic:
    - revisionName: serving-app-00001
      percent: 50
    - revisionName: serving-app-00002
      percent: 50

Apply the updated Knative Service

kubectl apply -f knative-service.yaml

Use different domains to access specific revision(s)

  traffic:
    - revisionName: serving-app-00001
      percent: 50
    - revisionName: serving-app-00002
      percent: 50
    - revisionName: serving-app-00003
      percent: 0
      tag: test

Apply the updated Knative Service

kubectl apply -f knative-service.yaml

Add a new entry to hosts file

Unix: /etc/hosts
Windows: C:\Windows\System32\drivers\etc\hosts

Entry value

127.0.0.1       test-serving-app.default.example.com

3.3 Clean up Knative Services

Delete revision

kubectl delete revision serving-app-00001

Delete Knative Service

kubectl delete ksvc serving-app
view raw README.md hosted with ❤ by GitHub
apiVersion: v1
kind: ConfigMap
metadata:
name: config-autoscaler
namespace: serving
data:
enable-scale-to-zero: "false"
scale-to-zero-grace-period: "30s"
scale-to-zero-pod-retention-period: "0s"
container-concurrency-target-default: "100"
container-concurrency-target-percentage: "0.7"
max-scale-up-rate: "1000"
max-scale-down-rate: "2"
panic-window-percentage: "10"
panic-threshold-percentage: "200"
stable-window: "60s"
target-burst-capacity: "200"
requests-per-second-target-default: "200"
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: serving-app
namespace: default
spec:
template:
spec:
containers:
- image: bsucaciu/knative-serving:v2
env:
- name: MESSAGE
value: Hello
traffic:
- revisionName: serving-app-00001
percent: 50
- revisionName: serving-app-00002
percent: 50
- revisionName: serving-app-00003
percent: 0
tag: test
Subscribe
Notify of
guest


0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x