BLOG ARTICLE 자동화 | 3 ARTICLE FOUND

  1. 2020.11.12 Gitlab CE , EE
  2. 2020.06.26 CI/CD와 도구들
  3. 2020.06.25 테라폼(Terraform)으로 AWS EC2 생성/제거 하기

Gitlab CE , EE

자동화 2020. 11. 12. 00:03

CE는 무료, EE는 유료.

하지만 EE 쓰면서 core만 사용하면 무료로 사용 가능.

CE->EE로 업글하려면 마이그레이션 같은 작업이 필요한데 EE Core->유료로 변경은 명령 한줄로 되는거라 무료를 사용한다면 CE보다 EE Core를 권장한다고 함

https://uxgjs.tistory.com/192

 

 

EE의 비용은 어디까지 기능을 사용할지에 따라 다름

Gitlab을 직접 설치해 사용하는 경우 Core, Starter, Premium, Ultimate 라고 부르고, Gitlab.com에서 서비스를 제공받으면 Free, Bronze, Silver, Gold 라고 부름

https://about.gitlab.com/pricing/

 

 

Tier에 따라 제공하는 기능이 엄청 많음

Core는 혼자쓰기용으로 보임, Starter 부터를 함께쓰기 기능이 많이 보임. Ultimate는 대시보드나 가시성 좋게 예쁘게 보이게 하는 기능이 많이 보임

나중에 개발하는 친구들에게 물어보자.

https://about.gitlab.com/features/#compare

https://about.gitlab.com/features/by-paid-tier/

 

 

AND

CI/CD와 도구들

자동화 2020. 6. 26. 02:41

CI/CD는?

CI (Continuous Integration)

개발자가 변경한 코드를 빌드하고 테스트를 거쳐 리포지토리에 업로드 하는 과정을 자동화 한다.

관련 제품 : Jenkins, Travis

 

 

CD (Continuous Delivery/Deployment)

리포지토리의 코드를 받아 라이브 환경에 배포하는 과정을 자동화 한다.

관련 제품들

관련 제품 : Spinnaker

 

 

CI/CD를 위한 도구들

Packer

가상머신의 표준 이미지를 만든다

AWS AMI, Azure Image, Google Cloud Image도 만들어서 클라우드에 등록해두고 사용할 수 있다.

Ansible과 조합해서 세부적인 구성이 변경되어야 하는 경우 Ansible 스크립트만 업데이트 해서 표준 이미지 업데이트까지 일어나지 않도록 하면서 운영한다.

비슷한 도구로 Vagrant가 있다.

 

Terraform

클라우드 환경 구성을 자동화 한다.

구성, 변경, 제거를 코드로 구현하고 동작시켜 자동화 한다.

 

Ansible

VM이 만들어진 후 개발, DB, Web 등의 환경 구성을 자동화 한다.

Packer로 이미지 생성해 사용할 때 이미지로 VM생성 후 Ansible로 특정 환경 구성을 자동화 한다.

프로비저닝 코드를 만든다고 표현한다.

 

Jenkins

CI용 도구들 중 가장 많이 추천하는 도구로 보임.

내가 변경한 코드의 코딩 규약 체크, 자동화 테스트 수행, 컴파일 오류 확인, 설능 변화 감시 등을 제공.

 

Spinnaker

Netflix에서 개발한 CD를 위한 도구. VM이나 컨테이너 기반에서도 동작 함. 배포시 테스트를 거치고 새로운 버전으로 자연스럽게 전환할 수 있도록 한다. 

 

 

활용

1. Terraform으로 웹용 VM 생성 후 Ansible로 웹서버를 구성.

Jenkins에서 빌드된 결과를 받아서 코드 배포.

구성된 VM을 LB에 추가 함.

 

2. Packer를 이용해 기본 구성이 완료되어 있는 이미지를 미리 만들어 두고 이를 이용해서 VM 생성

생성된 VM에 어플리케이션 코드 최종본을 배포해서 구성 완료.

 

3. Spinnaker를 이용해 Blue/Green, Canary, Rolling 방식 등의 다양한 배포 방식을 이용

복잡한 네트워크 설정이나 Cloud SQL 같은 클라우드 서비스는 Spinnaker로 설정이 불가능하기 때문에 인프라 부분은 Terraform으로 구성해야 한다.

 

 

 

 

== 참고

https://www.redhat.com/ko/topics/devops/what-is-ci-cd

https://bcho.tistory.com/1234

 

 

AND

.

 

테라폼 windows 64bit 버전 다운로드 받아 사용

https://www.terraform.io/downloads.html

 

 

D:\Util\terraform>terraform -version
Terraform v0.12.27

 

같은 폴더에 <mytest.tf> 파일 생성

provider "aws" {
  access_key = "ACCESS KEY"
  secret_key = "SECRET KEY"
  region     = "ap-northeast-2"
}

resource "aws_instance" "example" {
  ami           = "ami-f293459c"
  instance_type = "t2.micro"
}

 

D:\util\terraform> terraform init

tf파일을 확인하여 필요한 provider를 다운받는다. 여기서는 aws provider가 필요 함.

- Checking for available provider plugins...
- Downloading plugin for provider "aws" (hashicorp/aws) 2.67.0...

 

 

D:\util\terraform> terraform plan

tf 파일이 수행되면 어떤 변경들이 발생하는지 보여준다.

명령 실행 후 할당되는 정보들은 (known after apply)라고 표시되는것을 알 수 있다.

Refreshing Terraform state in-memory prior to plan... 
The refreshed state will be used to calculate this plan, but will not be 
persisted to local or remote state storage. 

------------------------------------------------------------------------ 

An execution plan has been generated and is shown below. 
Resource actions are indicated with the following symbols: 
  + create 

Terraform will perform the following actions: 

  # aws_instance.example will be created 
  + resource "aws_instance" "example" { 
      + ami                          = "ami-f293459c" 
      + arn                          = (known after apply) 
      + associate_public_ip_address  = (known after apply) 
      + availability_zone            = (known after apply) 

~~~~ 생략 ~~~~ 

Plan: 1 to add, 0 to change, 0 to destroy. 

------------------------------------------------------------------------ 

Note: You didn't specify an "-out" parameter to save this plan, so Terraform 
can't guarantee that exactly these actions will be performed if 
"terraform apply" is subsequently run.

 

 

D:\util\terraform> terraform apply

tf 파일을 적용한다. 기본적으로 "yes"라고 직접 타이핑 해야만 진행되도록 안전장치가 되어 있다.

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_instance.example will be created
  + resource "aws_instance" "example" {
      + ami                          = "ami-f293459c"
      + arn                          = (known after apply)
      + associate_public_ip_address  = (known after apply)
      + availability_zone            = (known after apply)

~~~~ 생략 ~~~~

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_instance.example: Creating...
aws_instance.example: Still creating... [10s elapsed]
aws_instance.example: Still creating... [20s elapsed]
aws_instance.example: Still creating... [30s elapsed]
aws_instance.example: Creation complete after 31s [id=i-0ad240b918ae149aa]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

 

이제 AWS 콘솔에 가서 보면 t2.micro 타입의 EC2가 생성된 것을 확인할 수 있다.

 

명령을 수행하고 나면 <terraform.tfstate> 파일이 자동으로 생성되는데 방금 생성한 EC2 정보를 여기서 확인할 수 있다.

이 상태 파일은 테라폼이 어떤 리소스를 관리하는지 알 수 있도록 하므로 여러 사람과 작업할 때 함께 공유되어야 한다.

이 정보는 다음 명령을 통해서도 확인 가능하다.

 

D:\util\terraform> terraform show

# aws_instance.example:
resource "aws_instance" "example" {
    ami                          = "ami-f293459c"
    arn                          = "arn:aws:ec2:ap-northeast-2:277773220743:instance/i-0ad240b918ae149aa"
    associate_public_ip_address  = true
    availability_zone            = "ap-northeast-2c"
    cpu_core_count               = 1
    cpu_threads_per_core         = 1
    disable_api_termination      = false
    ebs_optimized                = false
    get_password_data            = false
    hibernation                  = false
    id                           = "i-0ad240b918ae149aa"
    instance_state               = "running"
    instance_type                = "t2.micro"
    ipv6_address_count           = 0
    ipv6_addresses               = []
    monitoring                   = false
    primary_network_interface_id = "eni-03fe16619d143d4e6"
    private_dns                  = "ip-172-31-46-213.ap-northeast-2.compute.internal"
    private_ip                   = "172.31.46.213"
    public_dns                   = "ec2-15-164-211-149.ap-northeast-2.compute.amazonaws.com"
    public_ip                    = "15.164.211.149"
    security_groups              = [
        "default",
    ]
    source_dest_check            = true
    subnet_id                    = "subnet-220a546e"
    tenancy                      = "default"
    volume_tags                  = {}
    vpc_security_group_ids       = [
        "sg-0c01d362",
    ]

~~~~ 이하생략 ~~~~

 

생성했던 인스턴스를 제거하기 위해서는 다음 명령을 수행한다. 생성할때와 마찬가지로 "yes"라고 직접 타이핑 해야만 진행되도록 안전장치가 되어 있다.

D:\util\terraform> terraform destroy

aws_instance.example: Refreshing state... [id=i-0ad240b918ae149aa]
Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

 

 

 

== 참고

terraform : https://www.terraform.io/

테라폼 기초 튜토리얼 : https://www.44bits.io/ko/post/terraform_introduction_infrastrucute_as_code

테라폼101 : https://mooyoul.github.io/2016/12/19/Terraform-101/

 

AND