DOCKER CODE LINK – https://github.com/KubernetesSchool/Knative-Resources/tree/main/docker
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
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
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
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
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
Delete revision
kubectl delete revision serving-app-00001
Delete Knative Service
kubectl delete ksvc serving-app
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 |
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND