challenges-cloudformation-jenkins
challenges-cloudformation-jenkins copied to clipboard
:school: Challenges Your AWS And Cloudformation Skills By Solving Real Questions.
- Challenges Your AWS Cloudformation Skills :AWS: :PROPERTIES: :type: cloudformation :END:
Deploy Jenkins via AWS Cloudformation. Scenario-by-scenario.
[[image-blog:Challenges Your AWS Cloudformation Skills][https://raw.githubusercontent.com/DennyZhang/challenges-cloudformation-jenkins/master/images/cloud-formation.png]]
- Blog URL: https://www.dennyzhang.com/challenges-cloudformation-jenkins
- Category: [[https://www.dennyzhang.com/category/AWS/][AWS]]
File me [[https://github.com/DennyZhang/challenges-cloudformation-jenkins/issues][Issues]] or star [[https://github.com/DennyZhang/challenges-cloudformation-jenkins][this repo]].
See more challenges from Denny: [[https://github.com/topics/denny-challenges][#denny-challenges]]
** Scenario-101: Docker Single-Node Jenkins Deployment I
- Objective: Deploy Docker container in AWS
- Requirements: #+BEGIN_EXAMPLE
- Start an EC2 instance by cloudformation
- Provision the instance as docker daemon
- Setup Jenkins container inside the instance #+END_EXAMPLE
- Main Tech: Cloudformation, Docker
[[https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=aws-jenkins&templateURL=https://s3.amazonaws.com/aws.dennyzhang.com/cf-jenkins-main-101.yml][https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png]]
- See more: [[https://github.com/dennyzhang/challenges-cloudformation-jenkins/tree/master/Scenario-101][Scenario-101]]
** Scenario-102: Docker Single-Node Jenkins Deployment II
- Objective: Customize Jenkins docker deployment in AWS
- Requirements: #+BEGIN_EXAMPLE
- Finish Scenario-101, create a jenkins user by code.
- Anonymous user can't open the jenkins. Only login user can.
- When Jenkins is down, get alerts
- Make sure Jenkins GUI changes can be seamlessly tracked in git repo. #+END_EXAMPLE
- Main Tech: Cloudformation, Docker
[[https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=aws-jenkins&templateURL=https://s3.amazonaws.com/aws.dennyzhang.com/cf-jenkins-main-102.yml][https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png]]
- See more: [[https://github.com/dennyzhang/challenges-cloudformation-jenkins/tree/master/Scenario-102][Scenario-102]]
** Scenario-201: VM Single-Node Jenkins Deployment I
- Objective: We need a live Jenkins env in public Cloud. Fast and easy.
- Requirements: #+BEGIN_EXAMPLE
- Use cloudformation to start an EC2 instance
- Start Jenkins inside the EC2 instance #+END_EXAMPLE
- Main Tech: Cloudformation, Chef
[[https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=aws-jenkins&templateURL=https://s3.amazonaws.com/aws.dennyzhang.com/cf-jenkins-main-201.yml][https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png]]
- See more: [[https://github.com/dennyzhang/challenges-cloudformation-jenkins/tree/master/Scenario-201][Scenario-201]]
** Scenario-202: VM Single-Node Jenkins Deployment II
- Objective: Customize Jenkins docker deployment in AWS
- Requirements: #+BEGIN_EXAMPLE
- Finish Scenario-201, create a jenkins user by code.
- Create a dedicated VPC for the jenkins. And allow selective source IP to access.
- Anonymous user can't open the jenkins. Only login user can.
- Make sure Jenkins GUI changes can be seamlessly tracked in git repo. #+END_EXAMPLE
- Main Tech: Cloudformation, Chef, VPC, Slack
[[https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=aws-jenkins&templateURL=https://s3.amazonaws.com/aws.dennyzhang.com/cf-jenkins-main-202.yml][https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png]]
- See more: [[https://github.com/dennyzhang/challenges-cloudformation-jenkins/tree/master/Scenario-202][Scenario-202]]
** Scenario-203: VM Single-Node Jenkins Deployment III
- Objective: Customize Jenkins docker deployment in AWS
- Requirements: #+BEGIN_EXAMPLE
- Finish Scenario-202
- Use CF to create a dedicated VPC and start an EC2 #+END_EXAMPLE
- Main Tech: Cloudformation, Chef, VPC, CloudWatch, Slack
[[https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=aws-jenkins&templateURL=https://s3.amazonaws.com/aws.dennyzhang.com/cf-jenkins-main-203.yml][https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png]]
- See more: [[https://github.com/dennyzhang/challenges-cloudformation-jenkins/tree/master/Scenario-203][Scenario-203]]
** Scenario-301: VM ASG/ELB Jenkins Deployment I
- Objective: Customize Jenkins docker deployment in AWS
- Requirements: #+BEGIN_EXAMPLE
- Use CF to create ASG and ELB. And monitor ELB
- Start Jenkins master by ELB. Configure instance count to 1 #+END_EXAMPLE
- Main Tech: Cloudformation, Chef, VPC, CloudWatch, Slack
[[https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=aws-jenkins&templateURL=https://s3.amazonaws.com/aws.dennyzhang.com/cf-jenkins-main-301.yml][https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png]]
- See more: [[https://github.com/dennyzhang/challenges-cloudformation-jenkins/tree/master/Scenario-301][Scenario-301]]
** Scenario-302: VM ASG/ELB Jenkins Deployment II
- Objective: Customize Jenkins docker deployment in AWS
- Requirements: #+BEGIN_EXAMPLE
- Finish Scenario-301
- Get slack notificaiton for autoscaling events. Here we assume, one SNS topic has already been created. Verify it by terminating existing instance
- In ELB, enable monitoring Verify it by terminating existing instance
- In Jenkins deployment, create a pipeline #+END_EXAMPLE
- Main Tech: Cloudformation, Chef, VPC, CloudWatch, Slack
[[https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=aws-jenkins&templateURL=https://s3.amazonaws.com/aws.dennyzhang.com/cf-jenkins-main-302.yml][https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png]]
- See more: [[https://github.com/dennyzhang/challenges-cloudformation-jenkins/tree/master/Scenario-302][Scenario-302]]
** Scenario-303: VM ASG/ELB Jenkins Deployment II
- Objective: Customize Jenkins docker deployment in AWS
- Requirements: #+BEGIN_EXAMPLE
- Finish Scenario-302
- ELB export target group
- Enable logging for ELB
- When SNSTopicName is empty, avoid adding SNS notification #+END_EXAMPLE
- Main Tech: Cloudformation, Chef, VPC, CloudWatch, Slack
[[https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=aws-jenkins&templateURL=https://s3.amazonaws.com/aws.dennyzhang.com/cf-jenkins-main-302.yml][https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png]]
- See more: [[https://github.com/dennyzhang/challenges-cloudformation-jenkins/tree/master/Scenario-303][Scenario-303]]
** Scenario-401: VM 2-Nodes Jenkins Deployment I
- Objective: Avoid SPOF by adding 2 Jenkins instance
- Requirements: #+BEGIN_EXAMPLE
- Start 1 jenkins master and 1 jenkins slave
- Jenkins master offload request to jenkins slave #+END_EXAMPLE
- Main Tech: Cloudformation, Chef, VPC, CloudWatch, Jenkins Slack Integration, ALB
[[https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=aws-jenkins&templateURL=https://s3.amazonaws.com/aws.dennyzhang.com/cf-jenkins-main-401.yml][https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png]]
- See more: [[https://github.com/dennyzhang/challenges-cloudformation-jenkins/tree/master/Scenario-401][Scenario-401]]
- TODO: how the 2 Jenkins instance gonna to coordinate with each other?
** Scenario-402: VM 2-Nodes Jenkins Deployment II
- Objective: Jenkins cluster deployment
- Requirements: #+BEGIN_EXAMPLE
- Start 1 jenkins master and 1 jenkins slave
- Enable auto-scaling for Jenkins master. With instance count 1
- Enable auto-scaling for Jenkins slaves. With instance count range from 1 to 3
- Customized VPC to allow limited network access #+END_EXAMPLE
- Main Tech: Cloudformation, Chef, VPC, CloudWatch, EBS, Jenkins Slack Integration, ALB
[[https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=aws-jenkins&templateURL=https://s3.amazonaws.com/aws.dennyzhang.com/cf-jenkins-main-402.yml][https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png]]
- See more: [[https://github.com/dennyzhang/challenges-cloudformation-jenkins/tree/master/Scenario-402][Scenario-402]]
** Scenario-501: ECS Jenkins Deployment I
- Objective: Get exposed to docker orchestration service.
- Requirements: #+BEGIN_EXAMPLE
- Start ECS with 1 node
- Install a single Jenkins instance #+END_EXAMPLE
- Main Tech: Cloudformation, ECS, EBS
[[https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=aws-jenkins&templateURL=https://s3.amazonaws.com/aws.dennyzhang.com/cf-jenkins-main-501.yml][https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png]]
- See more: [[https://github.com/dennyzhang/challenges-cloudformation-jenkins/tree/master/Scenario-501][Scenario-501]]
** Scenario-502: ECS Jenkins Deployment II
- Objective: Deploy a 2-nodes Jenkins cluster
- Requirements: #+BEGIN_EXAMPLE
- Start ECS with 2 node
- Start Jenkins service with 2 instances in ECS. One for master, one for slave.
- Enable ALB for Jenkins master #+END_EXAMPLE
- Main Tech: Cloudformation, ECS, ELB, CloudWatch, ALB
[[https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=aws-jenkins&templateURL=https://s3.amazonaws.com/aws.dennyzhang.com/cf-jenkins-main-502.yml][https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png]]
- See more: [[https://github.com/dennyzhang/challenges-cloudformation-jenkins/tree/master/Scenario-502][Scenario-502]]
- TODO: How to avoid Jenkins SPOF, theoretically speaking?
** Scenario-503: ECS Jenkins Deployment III
- Objective: Deploy Jenkins 1 Master 3 Slaves with 2 nodes in ECS2
- Requirements: #+BEGIN_EXAMPLE
- Start ECS with 2 node
- Start Jenkins service within ECS. 1 Master and 3 Slaves
- Enable ALB for Jenkins master #+END_EXAMPLE
- Main Tech: Cloudformation, ECS, ELB, CloudWatch, ALB
[[https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=aws-jenkins&templateURL=https://s3.amazonaws.com/aws.dennyzhang.com/cf-jenkins-main-503.yml][https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png]]
- See more: [[https://github.com/dennyzhang/challenges-cloudformation-jenkins/tree/master/Scenario-503][Scenario-503]]
- TODO: How to avoid Jenkins SPOF, theoretically speaking?
** Scenario-601: Large Scale Jenkins Deployment I
- Objective: Suppose you have 1K developers to use your Jenkins. Improve scalability, availability, security, etc.
- Requirements: #+BEGIN_EXAMPLE
- Scalability: multiple Jenkins master instances
- Availability: Jenkins slave; Jenkins Master
- Security: VPC, Jenkins authentication integration #+END_EXAMPLE
- Main Tech: Cloudformation, ECS, EBS, ALB
[[https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=aws-jenkins&templateURL=https://s3.amazonaws.com/aws.dennyzhang.com/cf-jenkins-main-601.yml][https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png]]
- See more: [[https://github.com/dennyzhang/challenges-cloudformation-jenkins/tree/master/Scenario-601][Scenario-601]]
#+BEGIN_HTML
#+END_HTML
** Highlights
- Highlights For This Case Study #+BEGIN_EXAMPLE
- OS support: Amazon AMI, Ubuntu and CentOS
- Use CF to fully automate all deployments
- Auto-healing: autoscaling group. Improved service availability
- When issues have happened, we detect it earlier.
- Pretty secured
- Quick learner: I have never used CF before. This GitHub repo is the deliverable of 1.5 weeks' part time work. #+END_EXAMPLE
- Discussions & Further Improvements:
TOOD #+BEGIN_EXAMPLE 0. Use docker/ecs/k8s
- Speed up the whole setup process
- Reduce the deployment failure rate
- Improve master HA by using EFS for shared storage of Jenkins HOME
- Setup 1 master N slaves models
- Improve error handling. e.g, False positive. when EC2 instance is up, but chef apply hasn't finished
- Save the cloud bills
- Use serverless instead of Jenkins hosted solution
- Use CodeDeploy to replace Chef #+END_EXAMPLE
- Personal Review: #+BEGIN_EXAMPLE
- Really like container/ECS deployment over VM deployment.
- Jenkins community don't have HA solution for Jenkins master yet.
- Jenkins plugins dependency is really troublesome. #+END_EXAMPLE
- Critical Info #+BEGIN_SRC sh
Centos Jenkins Conf
/etc/sysconfig/jenkins
Run chef deployment
chef-solo --config "/home/ec2-user/chef/solo.rb"
--log_level auto -L "/home/ec2-user/log/run_chef_solo.log"
--force-formatter --no-color
--json-attributes "/home/ec2-user/chef/node.json"
#+END_SRC
- More Resources License: Code is licensed under [[https://www.dennyzhang.com/wp-content/mit_license.txt][MIT License]].
- Useful links #+BEGIN_EXAMPLE https://github.com/widdix/aws-cf-templates https://github.com/awslabs/startup-kit-templates http://templates.cloudonaut.io/en/stable/jenkins/
Jenkins Security
https://wiki.jenkins.io/display/JENKINS/Standard+Security+Setup https://d0.awsstatic.com/whitepapers/DevOps/Jenkins_on_AWS.pdf #+END_EXAMPLE
- org-mode configuration :noexport:
#+STARTUP: overview customtime noalign logdone hidestars
#+TITLE: Challenges Your AWS Cloudformation Skills
#+DESCRIPTION:
#+KEYWORDS:
#+AUTHOR: Denny Zhang
#+EMAIL: [email protected]
#+TAGS: noexport(n)
#+PRIORITIES: A D C
#+OPTIONS: H:3 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:t pri:nil tags:not-in-toc
#+EXPORT_EXCLUDE_TAGS: exclude noexport
#+SEQ_TODO: TODO HALF ASSIGN | DONE BYPASS DELEGATE CANCELED DEFERRED
#+LINK_UP:
#+LINK_HOME: