0
votes

I was performing AWS Blue/Green deployment to test a basic apache server and as CodeDeploy goes through 4 steps of B/G deployment it stuck at step 3 i.e, Routing traffic to replacement instances for about half-hour. I am not able to figure out what's wrong even after spending a long time and a couple of retries. I don't know whether my setup is correct or not. Here is my setup for B/G deployment.

  1. Created an autoscaling group named orginalautoscalinggroup with two instances.
  2. Creted two target groups one for original env and second for replacement env namely originaltargetgroup & replacementtargetgroup.
  3. Attached originaltargetgroup to be a part of originalautoscalinggroup.
  4. Created an application load balancer namely apploadbalancer and attached it with originaltargetgroup
  5. Now apploadbalancer is attached with originaltargetgroup which is attached with the originalautoscalinggroup.

My Codedeploy B/G configuration looks like this.

  1. Deployment Type: B/G
  2. Env configuration: Automatically copy Amazon EC2 Auto Scaling group
  3. Amazon EC2 Autoscaling group: originalautoscalinggroup
  4. Traffic rerouting: Reroute traffic immediately
  5. Termination policy: Terminate the original instances in the deployment group
  6. Deployment configuration: CodeDeployDefault.AllAtOnce
  7. Application load balancer.
  8. Target group: originaltargetgroup

I think I am not able to attach correct load balancer or target group. Please help.

Image1

Image2

1
Can you post screenshots of CodeDeploy deployment where it is stuck? Also, is it stuck in rerouting the traffic or is it struck after traffic is rerouted? - saurabh14292
@saurabh14292 I have added two images Image1 & Image2 please check it out. Also, it got stuck at Allow Traffic so I stopped the deployment. Please help as I have spent a long time trying out B/G deployment but couldn't get the right way. - marshmello
Have you checked if 1. New instances span up because of new ASG are registered to TargetGroup of LoadBalancer? 2. New instances are in "healthy" state so that they can server the traffic. - saurabh14292
@saurabh14292 Whenever I create an autoscaling group it launches two instances [empty] not reachable by their ip's so they are marked unhealthy by the target groups and I am trying to install the application on these fresh instances and maybe because instances are unhealthy (due to their success codes) It got stuck at allowtraffic showing error instances are unhealthy. So how do I cope with the success code and healthy state of instances? - marshmello
So my question is how do I make fresh instances reachable as they will always remain unhealthy because nothing is configured on them to make them reachable. - marshmello

1 Answers

0
votes

Adding answer based on comments.

Since the B/G deployment is failing during traffic rerouting, specifically at "Allow Traffic", instances are in "Unhealthy" state.

If the required services are not running on EC2 and are not reachable, they will remain in unhealthy state and traffic cannot be redirected to them, hence deployment will fail.

To make sure required services/processes are running on EC2 servers started by AutoScaling group, you

  1. Update the Launch Config/Template with "User Data" to execute the script on EC2 startup, which will install, configure and start the required services, say Nginx on port 80.
  2. You can create a custom AMI which has required application already installed in it and on EC2 startup, required service/process will start.

This way, whenever a new EC2 is started by ASG, it will go into healthy state depending on time required to start the process. Once it is healthy, it will be ready to server the traffic and post that, old instances will get de-registered.

Once old instances are de-registered, they may get terminated based on configurations in CodeDeploy.