이번주부터 강의를 집중해서 들어야 한다
새로 배우게 될 것들이 많기 때문에 블로그 포스팅도 다시 시작
- IaC 개요
InfraStructure as Code : 인프라 구성을 코드를 통해 자동으로 구축, 관리, 프로비저닝
프로비저닝-Provisioning
클라우드 서비스를 시작하고 구성하는 것을 프로비저닝이라 함
인프라를 설정하는 프로세스로 시스템, 데이터, 네트워크 작동을 준비하는 과정을 의미함
형상관리-Configuration Management
이력관리
서버 운영상 필요한 소프트웨어를 설치하고 설정으로 관리하는 것
설정 관리에 사용되는 여러 정보 이력을 관리
배포-deploy
프로비저닝된 서버를 실행시키기 위해 애플리케이션 버전을 제공하는 작업
오케스트레이션-orchestration
여러 시스템 또는 서비스를 조정하는 것
오케스트레이션의 목표는 배포, 관리, 확장, 네트워킹 자동화
IaC tools
AWS CloudFormation - AWS 에서 제공하는 IaC 서비스
Ansible
별도의 Agent 없이 IaC 서비스 제공
SSH 기반으로 IaC 서비스 제공
Puppet
Chef
Terraform - GUI 기반으로 IaC 서비스 제공
기타...
- AWS CloudFormation
클라우드 포메이션
https://aws.amazon.com/ko/cloudformation/
코드형 인프라 프로비저닝 - AWS CloudFormation - Amazon Web Services
CloudFormation Registry, 개발자 커뮤니티 및 자체 라이브러리에 게시된 클라우드 리소스를 포함하도록 인프라를 확장하고 관리할 수 있습니다.
aws.amazon.com
클라우드 포메이션 소개
https://docs.aws.amazon.com/ko_kr/AWSCloudFormation/latest/UserGuide/Welcome.html
AWS CloudFormation이란 무엇인가요? - AWS CloudFormation
AWS CloudFormation이란 무엇인가요? AWS CloudFormation은 AWS 리소스를 모델링하고 설정하여 리소스 관리 시간을 줄이고 AWS에서 실행되는 애플리케이션에 더 많은 시간을 사용하도록 해 주는 서비스입니
docs.aws.amazon.com
AWS의 대표적인 IaC 구성 조정 도구
장점
- 인프라 관리 간소화
- 신속하게 인프라 복제
- 인프라 변경 사항 제어와 추적 용이
- 무료
JSON 또는 YAML 을 이용해 작성함
JSON - https://www.json.org/
각 요소를 작성할때 tab 간격을 사용하여 작성함
key : value 형식
확장자 .json
YAML - https://yaml.org/
각 요소를 작성할 때 space 2칸으로 들여쓰기함
key : value 형식
확장자 .yaml , .yml
AWS CloudFormation 구성요소
템플릿 - Template
- 스택 리소스 프로비저닝 및 구성을 위해 필요한 텍스트 파일
- JSON 또는 YAML 형식의 파일로 작성
- AWS CloudFormation Designer 를 사용해 GUI 기반으로 작성할 수 있다 - 불필요한 코드가 템플릿에 추가될 수 있음
- AWS CloudFormation 템플릿을 AWS 리소스 구축을 위한 blueprint로 사용
스택 - Stack
- 하나의 단위로 관리할 수 있는 AWS 리소스 모음
- 스택의 생성, 업데이트, 삭제를 통해 리소스 모음의 생성, 업데이트, 삭제
- 스택의 모든 리소스는 AWS CloudFormation 템플릿을 통해 정의
- 스택을 삭제하면 스택에 의해 생성된 모든 리소스도 같이 삭제
AWS CloudFormation 작동방식
json 또는 yaml 포맷으로 aws cloudformation 템플릿 작성 - 구성하려고 하는 aws 리소스에 대한 정보 기술
작성된 템플릿을 s3 버킷에 저장 - 로컬 or s3 버킷
템플릿 위치를 지정하여 cloudformation 스택 생성
템플릿에 지정된 스택을 통해 aws 리소스에 대한 프로비저닝 및 구성 작업 진행
AWS CloudFormation 템플릿 구성 요소
AWS TemplateFormatVersion (선택사항)
- 템플릿 버전
- 디폴트 - 최신 버전
Metadata(선택사항)
- 템플릿에 대한 추가 정보 제공
- CloudFormation 은 Metadata 섹션에 포함된 정보를 변환, 수정, 삭제 하지 않음
- 주석같은 느낌
Parameter(선택사항)
- 스택을 생성하거나 업데이트 할 때 실행 시 템플릿에 전달하는 값
- 최대 60개 파라미터 지정 가능
- 파라미터는 동일한 템플릿에서 선언하고 참조해야 함
- 파라미터 참조시에는 !ref <파라미터이름> 형식 사용
Mappings(선택사항)
조건부 파라미터 값을 지정하는 데 사용할 수 있는 키와 관련 값의 매핑
Resources(필수사항)
AWS 리소스 및 해당 속성 지정
Logical ID - Resource 식별자, 논리적 ID, 영어와 숫자로만 이루어저야 하고 고유한 값을 가져야 함
Resource type - 선언하려는 리소스 유형을 식별
Properties - 리소스에 지정할 수 있는 추가 옵션
outputs(선택사항)
- 스택 속성을 볼 때마다 반환하는 값 설명
- CloudFormation은 outputs 섹션에 포함된 정보를 삭제하거나 난독화 하지 않음
- 최대 60개 출력 가능
AWS CloudFormation 템플릿
메인
https://aws.amazon.com/ko/cloudformation/resources/templates/
CloudFormation 템플릿
샘플 솔루션 템플릿은 일반적인 애플리케이션으로 엔드 투 엔드 솔루션을 생성하는 방법을 보여줍니다. AWS는 이 샘플 내 애플리케이션을 지원하거나 유지 관리하지 않습니다. 샘플은 AWS CloudForm
aws.amazon.com
sample 조각
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/CHAP_TemplateQuickRef.html
Template snippets - AWS CloudFormation
Thanks for letting us know this page needs work. We're sorry we let you down. If you've got a moment, please tell us how we can make the documentation better.
docs.aws.amazon.com
application framework
Application frameworks - AWS CloudFormation
Thanks for letting us know this page needs work. We're sorry we let you down. If you've got a moment, please tell us how we can make the documentation better.
docs.aws.amazon.com
- Ansible 개요
IaaS - Infrastructure as a Service
- 클라우드를 통해 가상머신 환경을 온디멘드로 제공
- RedHat 에서 개발
- 오픈소스 방식으로 서버의 프로비저닝, SW 배포 등의 자동화를 관리해주는 도구
Ansible 특징
Agentless - ansible은 타겟 대상들에 agentless 기반의 push 방식으로 동작하므로 기술적, 지리적 제한이 보다 넓다
멱등성(Idempotency) - 어떤 연산이 여러번 수행되더라도 결과가 달라지지 않는 성질
재사용성(Reusability) - 기준 시스템 구성 정보를 재사용하여 손쉽게 인프라 구성 관리 수행
참고
Ansible Documentation
Ansible Automation Controller Documentation Access the best of Ansible innovation with hardening and support from Red Hat. Learn how the elements of the Automation Controller work together with Red Hat Ansible Automation Platform to centralize and control
docs.ansible.com
https://www.redhat.com/ko/topics/automation/learning-ansible-tutorial
Ansible 기초 강의: SSH 프로토콜, 앤서블 플레이북, 설치, 강의
Ansible은 프로비저닝, 오케스트레이션 등 IT 프로세스를 자동화합니다. ssh 프로토콜, 앤서블 플레이북, 앤서블 설치, 앤서블 예제, 앤서블 강의를 자세히 알아보세요.
www.redhat.com
- Ansible 구성 요소
제어 노드 - control node
Ansible 을 실행하는 노드
Ansible 제공 프로그램을 이용하여 다른 노드 관리
control node 와 managed node 사이에는 ssh 를 통해 통신함
관리 노드 - managed node
Ansible 로 관리하는 서버를 관리노드 또는 호스트, 타겟 이라고 한다
관리노드에는 앤서블이 설치되지 않음
인벤토리 - Inventory
타겟 노드 목록
인벤토리 파일은 호스트 파일이라고도 함
인벤토리 파일은 각 타겟 노드에 대한 IP add, 호스트 정보, 변수와 같은 정보를 저장
모듈 - Module
Ansible 이 실행하는 코드 단위
미리 만들어진 동작 관련 코드 집합
각 모듈은 db처리, 사용자 관리, 네트워크 장치 관리 등 다양한 용도로 사용됨
단위 모듈을 호출하거나 playbook 에서 여러 모듈을 호출할 수 있다
테스크 - Task
Ansible 작업 단위
Ad-hoc 명령을 사용하여 단일 작업 실행 가능
플레이북 - playbook
순서가 지정된 테스크 목록
지정된 작업을 해당 순서로 반복적으로 실행 가능
플레이북에는 변수와 작업이 포함될 수 있음
YAML 로 작성함
- Ansible 실습
ansible 프레임워크로 control node 에 ansible 을 설치해서 managed 되고있는 node instance 제어
- 실습환경 구축
EC2
ControlNode
- SG : SSH, HTTP, HTTPS
- keypair - 타겟 노드의 keypair 를 모두 가지고 있어야 함
ManagedNode1
ManagedNode2
- subnet : private
ManagedNode3
ControlNode 에 keypair 파일 업로드
- controlnode 와 managednode 는 ssh 로 연결되어 push 로 제어함
Ansible2 설치
sudo amazon-linux-extras install ansible2
ansible 환경설정 파일
sudo su - : root user 로 사용자 전환
/etc/ansible/ansible.cfg - ansible 환경 설정 파일
host_key_checking = False - 제어노드에서 타겟노드 접속 시 key 확인 과정 생략
/etc/ansible/hosts - default inventory file
Ansible configuration file 적용 순서
1. ANSIBLE_CONFIG 환경 변수에 지정된 파일
2. 현재 디렉토리에 있는 ansible.cfg 파일
3. 사용자 홈 디렉토리에 있는 ansible.cfg 파일
4. (instance 내 모든 사용자-global) /etc/ansible/ansible.cfg 파일
Managed node와 연결 확인
host file (inventory)
ec2-user/work-ansible/hosts - /etc/ansible/hosts 파일을 복사해서 작업 디렉토리에서 사용 (현재 사용자용)
내용 :
[managed]
host1 ansible_host=(ec2 ip)
host2 ansible_host=(ec2 ip)
[managed:var]
ansible_connection=ssh
ansible_port=22
ansible_user=ec2_user ansible_private_key_file=(pem 파일 절대경로)
- Ad-hoc 명령
Ansible 은 일반적으로 playbook 을 사용하도록 설계
한번만 수행하거나 간단한 명령을 통한 상태확인 등은 별도의 playbook 을 구성할 필요 없이 Ad-hoc 으로 구현 가능
형식
ansible [타겟노드] [옵션]
- host1 에 ansible 내 ping 모듈을 사용한다
-m 모듈명 : 모듈 사용
-i 파일명 : 인벤토리 , default-/etc/ansible/hosts
-a 인수목록 : 모듈 인수
-k : 암호 확인
ex) $ ansible host1 -m ping -i ./hosts
ex) $ ansible managed -m ping -i ./hosts
- Inventory 이해
How to build your inventory — Ansible Documentation
Docs » User Guide » How to build your inventory How to build your inventory Ansible works against multiple managed nodes or “hosts” in your infrastructure at the same time, using a list or group of lists know as inventory. Once your inventory is defi
docs.ansible.com
Control node 에서 Managed node 에 연결하기 위한 정보를 가지고 있는 파일
기본 위치 : /etc/ansible/hosts
기본 위치의 파일은 default 로 적용되는 인벤토리 이고 관리자 권한으로만 수정 가능
사용자가 원하는 디렉토리에 복사한 후 편집하여 사용
- sudo cp /etc/ansible/hosts.
- sudo chown [사용자id]:[사용자그룹] [인벤토리파일]
Ansible 설치 후 인벤토리 내용의 사용법이 주석으로 적혀있다
# This is the default ansible 'hosts' file. # # It should live in /etc/ansible/hosts # # - Comments begin with the '#' character # - Blank lines are ignored # - Groups of hosts are delimited by [header] elements # - You can enter hostnames or ip addresses # - A hostname/ip can be a member of multiple groups # Ex 1: Ungrouped hosts, specify before any group headers. ## green.example.com ## blue.example.com ## 192.168.100.1 ## 192.168.100.10 # Ex 2: A collection of hosts belonging to the 'webservers' group ## [webservers] ## alpha.example.org ## beta.example.org ## 192.168.1.100 ## 192.168.1.110 # If you have multiple hosts following a pattern you can specify # them like this: ## www[001:006].example.com # Ex 3: A collection of database servers in the 'dbservers' group ## [dbservers] ## ## db01.intranet.mydomain.net ## db02.intranet.mydomain.net ## 10.25.1.56 ## 10.25.1.57 # Here's another example of host ranges, this time there are no # leading 0s: ## db-[99:101]-node.example.com |
- 인벤토리 내용
그룹을 지정하지 않는 방식
hostname [속성]
ex)
10.0.1.97 ansible_connection=ssh ansible_port=22 ansible_user=ec2-user ansible_ssh_private_key_file=/home/ec2-user/work-ansible/gurum-aicore0942-20220906.pem
host1 ansible_host=10.0.1.98 ansible_connection=ssh ansible_port=22 ansible_user=ec2-user ansible_ssh_private_key_file=/home/ec2-user/work-ansible/gurum-aicore0942-20220906.pem
그룹을 지정하는 방식
[그룹명]
[타겟노드] [속성]
ex)
[managed]
host1 ansible_host=10.0.1.97 ansible_connection=ssh ansible_port=22 ansible_user=ec2-user ansible_ssh_private_key_file=/home/ec2-user/work-ansible/gurum-aicore0942-20220906.pem
host2 ansible_host=10.0.1.97 ansible_connection=ssh ansible_port=22 ansible_user=ec2-user ansible_ssh_private_key_file=/home/ec2-user/work-ansible/gurum-aicore0942-20220906.pem
공통 정보를 변수에 저장하여 공유하는 방식
[그룹명:vars]
[속성값]
ex)
ansible_connection=ssh #연결 방법
ansible_port=22 #연결 port number
ansible_user=ec2-user #host( managed node ) user id
ansible_ssh_private_key_file=/home/ec2-user/work-ansible/gurum-aicore0942-20220906.pem #개인키 파일 위치
ansible_python_interpreter=/usr/bin/python3 #host( managed node ) python 경고 메시지를 출력하지 않도록 파이썬 인터프리터 위치 지정
여러 그룹을 하나의 그룹으로 묶어서 변수를 공유하는 방법
[그룹명:children]
[기존그룹1]
[기존그룹2]
ex)
[common:children]
managed
public
private
webserver
[common:vars]
ansible_connection=ssh
ansible_port=22
ansible_user=ec2-user
ansible_ssh_private_key_file=/home/ec2-user/work-ansible/gurum-aicore0942-20220906.pem
ansible_python_interpreter=/usr/bin/python3
cloudformation 은 스택으로 리소스를 한번에 생성+삭제 하는 거고
그렇게 생성한 다수 리소스들(여기선 ec2만?) 컨트롤하는데 사용하는것이 Ansible
'Kubernetes > [구름] 쿠버네티스 전문가 양성 과정 k-digital' 카테고리의 다른 글
[8주-9.22] playbook 이해 (0) | 2022.09.22 |
---|---|
[8주-9.21] Ansible - module, YAML, playbook 개요 (0) | 2022.09.21 |
[5주-20일차] (0) | 2022.08.30 |
[4주-19일차] (0) | 2022.08.26 |
[4주-18일차] 허리 좀 나았다 ㅠㅠ / DB서버 (0) | 2022.08.25 |