Onboard a Service with DTC
Introduction
Assuming your service is already being advertised by ExternalDNS, enabling weight management using the Dynamic Traffic Controller (DTC) is as easy as adding a label to the service.
note
This guide assumes you have already deployed ExternalDNS and have added ExternalDNS annotations for advertisement to your provider. If this is not true, see Getting Started with ExternalDNS.
Add the Label
The following code is an excerpt from a Service definition with ExternalDNS annotations already applied.
apiVersion: v1
kind: Service
metadata:
annotations:
external-dns.alpha.kubernetes.io/hostname: myapp.example.com
external-dns.alpha.kubernetes.io/ttl: "60"
external-dns.alpha.kubernetes.io/weight: "100"
labels:
app: nginx
name: myapp-internal-service
namespace: kubeslice-system
spec:
externalTrafficPolicy: Cluster
ipFamilyPolicy: SingleStack
ports:
- name: http
nodePort: 31569
port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
sessionAffinity: None
type: LoadBalancer
To enable weight management, add the avesha.dns.metrics.io/monitor: "true"
label as shown on the line below app: nginx
.
apiVersion: v1
kind: Service
metadata:
annotations:
external-dns.alpha.kubernetes.io/hostname: myapp.example.com
external-dns.alpha.kubernetes.io/ttl: "60"
external-dns.alpha.kubernetes.io/weight: "100"
labels:
app: nginx
avesha.dns.metrics.io/monitor: "true"
name: myapp-internal-service
namespace: kubeslice-system
spec:
externalTrafficPolicy: Cluster
ipFamilyPolicy: SingleStack
ports:
- name: http
nodePort: 31569
port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
sessionAffinity: None
type: LoadBalancer
Confirm Measurement
After the label is added, the service will be monitored by DTC. You can confirm
the DTC has picked up the service by viewing the logs for the dns-controller
pod. You can use a command similar to the one below, but with your unique pod
name.
kubectl logs dns-controller-5f7b7f7f9f-5j2xg -n kubeslice-system
You can watch for a few minutes as the Dynamic Traffic Controller collects historical usage values and calculates a moving average. An example of what this may look like is below.
{"level":"info","ts":"2022-09-09T20:08:26.801601081Z","msg":"Average history","service":"frontend-external","average":91,"history":"[ 91, 91, 91, 91, ]"}
{"level":"info","ts":"2022-09-09T20:08:26.80165393Z","msg":"Service: frontend-external, CPU Usage: 17.0 mCPU (8.5%), CPU Limits: 200.0 mCPU"}
{"level":"info","ts":"2022-09-09T20:08:26.801662125Z","msg":"Service: frontend-external, Current Weight: 91, Previous: 92, Not Significant, Only Updating Usage..."}
{"level":"info","ts":"2022-09-09T20:08:57.618496037Z","msg":"Average history","service":"frontend-external","average":91,"history":"[ 91, 91, 91, 91, 90, ]"}
{"level":"info","ts":"2022-09-09T20:08:57.618550069Z","msg":"Service: frontend-external, CPU Usage: 20.1 mCPU (10.1%), CPU Limits: 200.0 mCPU"}
{"level":"info","ts":"2022-09-09T20:08:57.618564776Z","msg":"Service: frontend-external, Current Weight: 91, Previous: 92, Not Significant, Only Updating Usage..."}
{"level":"info","ts":"2022-09-09T20:09:28.70038254Z","msg":"Average history","service":"frontend-external","average":91,"history":"[ 91, 91, 91, 91, 90, 90, ]"}
{"level":"info","ts":"2022-09-09T20:09:28.700446358Z","msg":"Service: frontend-external, CPU Usage: 20.1 mCPU (10.1%), CPU Limits: 200.0 mCPU"}
{"level":"info","ts":"2022-09-09T20:09:28.700454594Z","msg":"Service: frontend-external, Current Weight: 91, Previous: 92, Not Significant, Only Updating Usage..."}