Answers: <p>Closest solution I found so far is creating those two deployments with such number of pod replicas, that corresponds to the required ratio (or close to it). I.e. if the required ratio is 7:3, Deployment A would have 7 pods, Deployment B would have 3. Service being simple round-robin, should ensure the requests spread according to the ratio.</p>
  <p>It's not a very elegant solution though, this might be quite a big waste of resources in some cases.</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-03-28T20:15:26.797Z
Answers: 2022-03-28T20:15:26.797Z
Answers: David Lukac
Answers: <p>To keep a ratio between N deployments, you can use the HorizontalPodAutoscaler. One of your deployments is autoscaled on your traffic (for example average traffic per pod) and the other ones are autoscaled based on their relative weight (deployment target weight / sum of the weight of the deployments).</p>
  <p>Implementation details: you actually have to autoscaled on the inverse of the weight as the number of pods is inversely proportional to the weight.</p>
  
Answers: CC BY-SA 4.0
Answers: 2024-04-18T08:14:19.200Z
Answers: 2024-04-18T08:16:49.883Z
Answers: 2024-04-18T08:16:49.883Z
Answers: user3020921
Body: <p>Context: Kubernetes (1.23), 2 Deployments of the same app with different version/config/etc., 1 Service</p>
  <p>Let's say I have a web application deployed in Kubernetes using a Deployment. I want to add a new (canary, A/B testing) version of the same app as a new separate Deployment, so we're not touching the original Deployment. I want to set fixed ratio of traffic between these two Deployments.</p>
  <p>Is it possible to achieve this using Service, or other Kube native objects? (Not by utilizing a service mesh).</p>
  
Tags: <kubernetes><deployment><load-balance>
Title: Is it possible to split traffic by fixed ratio among two Deployments using only Service
UserDisplayName: David Lukac
ThreadText: # Is it possible to split traffic by fixed ratio among two Deployments using only Service
  
  (Asked by: username_0 on 2022-03-26)
  
  Context: Kubernetes (1.23), 2 Deployments of the same app with different version/config/etc., 1 Service
  
  Let's say I have a web application deployed in Kubernetes using a Deployment. I want to add a new (canary, A/B testing) version of the same app as a new separate Deployment, so we're not touching the original Deployment. I want to set fixed ratio of traffic between these two Deployments.
  
  Is it possible to achieve this using Service, or other Kube native objects? (Not by utilizing a service mesh).
  
  **Tags:** kubernetes, deployment, load-balance
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2022-03-28. Score: 0 | Accepted answer
  
  Closest solution I found so far is creating those two deployments with such number of pod replicas, that corresponds to the required ratio (or close to it). I.e. if the required ratio is 7:3, Deployment A would have 7 pods, Deployment B would have 3. Service being simple round-robin, should ensure the requests spread according to the ratio.
  
  It's not a very elegant solution though, this might be quite a big waste of resources in some cases.
  
  
  ---
  
  ### Answer by username_1 on 2024-04-18. Score: 0
  
  To keep a ratio between N deployments, you can use the HorizontalPodAutoscaler. One of your deployments is autoscaled on your traffic (for example average traffic per pod) and the other ones are autoscaled based on their relative weight (deployment target weight / sum of the weight of the deployments).
  
  Implementation details: you actually have to autoscaled on the inverse of the weight as the number of pods is inversely proportional to the weight.
  
  
  ---
  
  