becool

20210719 (월) 본문

openstack

20210719 (월)

gusalstm 2021. 7. 19. 17:23
반응형

탬플릿(파일)을 작성해서 스택을 배포

  스택 : 리소스들의 집합 

  탬플릿 : 변수등을 이용해서 리소스에 대한 정의

    탬플릿 → 스택 → 리소스

    탬플릿 작성 : openstack stack create

 ※ 정적스택 : 탬플릿에 리소스의 형태 및 크기를 고정

 ※ 동적스택 : 정적스택에 사용량에 대한 조건도 지정

 

[root@controller ~(keystone_admin)]# openstack orchestration template version list
+--------------------------------------+------+------------------------------+
| Version                              | Type | Aliases                      |
+--------------------------------------+------+------------------------------+
| AWSTemplateFormatVersion.2010-09-09  | cfn  |                              |
| HeatTemplateFormatVersion.2012-12-12 | cfn  |                              |
| heat_template_version.2013-05-23     | hot  |                              |
| heat_template_version.2014-10-16     | hot  |                              |
| heat_template_version.2015-04-30     | hot  |                              |
| heat_template_version.2015-10-15     | hot  |                              |
| heat_template_version.2016-04-08     | hot  |                              |
| heat_template_version.2016-10-14     | hot  | heat_template_version.newton |
| heat_template_version.2017-02-24     | hot  | heat_template_version.ocata  |
| heat_template_version.2017-09-01     | hot  | heat_template_version.pike   |
| heat_template_version.2018-03-02     | hot  | heat_template_version.queens |
+--------------------------------------+------+------------------------------+
[root@controller ~(keystone_admin)]# openstack orchestration resource type list
+----------------------------------------------+
| Resource Type                                |
+----------------------------------------------+
| AWS::AutoScaling::AutoScalingGroup           |
| AWS::AutoScaling::LaunchConfiguration        |
| AWS::AutoScaling::ScalingPolicy              |
| AWS::CloudFormation::Stack                   |
| AWS::CloudFormation::WaitCondition           |
| AWS::CloudFormation::WaitConditionHandle     |
| AWS::CloudWatch::Alarm                       |
| AWS::EC2::EIP                                |
| AWS::EC2::EIPAssociation                     |
| AWS::EC2::Instance                           |
| AWS::EC2::InternetGateway                    |
| AWS::EC2::NetworkInterface                   |
| AWS::EC2::RouteTable                         |
| AWS::EC2::SecurityGroup                      |
| AWS::EC2::Subnet                             |
| AWS::EC2::SubnetRouteTableAssociation        |
| AWS::EC2::VPC                                |
| AWS::EC2::VPCGatewayAttachment               |
| AWS::EC2::Volume                             |
| AWS::EC2::VolumeAttachment                   |
| AWS::ElasticLoadBalancing::LoadBalancer      |
| AWS::IAM::AccessKey                          |
| AWS::IAM::User                               |
| AWS::RDS::DBInstance                         |
| AWS::S3::Bucket                              |
| OS::Aodh::Alarm                              |
| OS::Aodh::CompositeAlarm                     |
| OS::Aodh::EventAlarm                         |
| OS::Aodh::GnocchiAggregationByMetricsAlarm   |
| OS::Aodh::GnocchiAggregationByResourcesAlarm |
| OS::Aodh::GnocchiResourcesAlarm              |
| OS::Cinder::EncryptedVolumeType              |
| OS::Cinder::QoSAssociation                   |
| OS::Cinder::QoSSpecs                         |
| OS::Cinder::Quota                            |
| OS::Cinder::Volume                           |
| OS::Cinder::VolumeAttachment                 |
| OS::Cinder::VolumeType                       |
| OS::Glance::Image                            |
| OS::Heat::AccessPolicy                       |
| OS::Heat::AutoScalingGroup                   |
| OS::Heat::CloudConfig                        |
| OS::Heat::DeployedServer                     |
| OS::Heat::InstanceGroup                      |
| OS::Heat::MultipartMime                      |
| OS::Heat::None                               |
| OS::Heat::RandomString                       |
| OS::Heat::ResourceChain                      |
| OS::Heat::ResourceGroup                      |
| OS::Heat::ScalingPolicy                      |
| OS::Heat::SoftwareComponent                  |
| OS::Heat::SoftwareConfig                     |
| OS::Heat::SoftwareDeployment                 |
| OS::Heat::SoftwareDeploymentGroup            |
| OS::Heat::Stack                              |
| OS::Heat::StructuredConfig                   |
| OS::Heat::StructuredDeployment               |
| OS::Heat::StructuredDeploymentGroup          |
| OS::Heat::SwiftSignal                        |
| OS::Heat::SwiftSignalHandle                  |
| OS::Heat::TestResource                       |
| OS::Heat::UpdateWaitConditionHandle          |
| OS::Heat::Value                              |
| OS::Heat::WaitCondition                      |
| OS::Heat::WaitConditionHandle                |
| OS::Keystone::Domain                         |
| OS::Keystone::Endpoint                       |
| OS::Keystone::Group                          |
| OS::Keystone::GroupRoleAssignment            |
| OS::Keystone::Project                        |
| OS::Keystone::Region                         |
| OS::Keystone::Role                           |
| OS::Keystone::Service                        |
| OS::Keystone::User                           |
| OS::Keystone::UserRoleAssignment             |
| OS::Neutron::AddressScope                    |
| OS::Neutron::ExtraRoute                      |
| OS::Neutron::FloatingIP                      |
| OS::Neutron::FloatingIPAssociation           |
| OS::Neutron::FlowClassifier                  |
| OS::Neutron::LBaaS::HealthMonitor            |
| OS::Neutron::LBaaS::L7Policy                 |
| OS::Neutron::LBaaS::L7Rule                   |
| OS::Neutron::LBaaS::Listener                 |
| OS::Neutron::LBaaS::LoadBalancer             |
| OS::Neutron::LBaaS::Pool                     |
| OS::Neutron::LBaaS::PoolMember               |
| OS::Neutron::MeteringLabel                   |
| OS::Neutron::MeteringRule                    |
| OS::Neutron::Net                             |
| OS::Neutron::NetworkGateway                  |
| OS::Neutron::Port                            |
| OS::Neutron::PortPair                        |
| OS::Neutron::ProviderNet                     |
| OS::Neutron::QoSBandwidthLimitRule           |
| OS::Neutron::QoSDscpMarkingRule              |
| OS::Neutron::QoSPolicy                       |
| OS::Neutron::Quota                           |
| OS::Neutron::RBACPolicy                      |
| OS::Neutron::Router                          |
| OS::Neutron::RouterInterface                 |
| OS::Neutron::SecurityGroup                   |
| OS::Neutron::SecurityGroupRule               |
| OS::Neutron::Subnet                          |
| OS::Neutron::SubnetPool                      |
| OS::Neutron::Trunk                           |
| OS::Nova::Flavor                             |
| OS::Nova::FloatingIP                         |
| OS::Nova::FloatingIPAssociation              |
| OS::Nova::HostAggregate                      |
| OS::Nova::KeyPair                            |
| OS::Nova::Quota                              |
| OS::Nova::Server                             |
| OS::Nova::ServerGroup                        |
| OS::Senlin::Cluster                          |
| OS::Senlin::Node                             |
| OS::Senlin::Policy                           |
| OS::Senlin::Profile                          |
| OS::Senlin::Receiver                         |
| OS::Swift::Container                         |
+----------------------------------------------+
[root@controller ~(keystone_admin)]# openstack orchestration resource type show OS::Nova::Server
openstack orchestration resource type show OS::Neutron::Net

 

탬플릿 구조  (p660)

heat_template_version 필수 탬플릿으로 제어해줄 오픈스택 버전
description 중요 주석을 달아주는 부분
탬플릿의 용도 및 주의사항 등
parameters 중요 탬플릿에서 사용할 변수를 선언
탬플릿의 재사용성을 증가
resources 핵심 각 리소스에 대한 선언
종류, 개수, 할당량 등을 설정
outputs 선택 작업 결과에 대해 출력 값(항목) 설정

 

탬플릿 생성 (p678) https://docs.openstack.org/heat/ocata/template_guide/hot_spec.html

 생성시 .yml .yaml 확장자로 생성

 yaml 언어를 사용 (ansible에서도 사용, 들여쓰기 횟수에 따른 레벨 구분)

 아래 .vimrc 파일을 생성하여 vim 에디터에서 yaml 들여쓰기 적용할 수 있음.

 heat-stack.yml 파일에 파라미터 값을 변수로 선언해둠으로써 재사용이 용이하게 됨.

 (NetID, ImageID, 

 

parameters:
  <param name>:
    type: <string | number | json | comma_delimited_list | boolean>
    label: <human-readable name of the parameter>
    description: <description of the parameter>
    default: <default value for parameter> → 기본값 설정 (ex. NetID : default : <network name>)
    hidden: <true | false>
    constraints:
      <parameter constraints>
    immutable: <true | false>

 

resources:
  my_instance:
    type: OS::Nova::Server
    properties:
      # general properties ...
      user_data:
        get_file: my_instance_user_data.sh
  my_other_instance:
    type: OS::Nova::Server
    properties:
      # general properties ...
      user_data:
        get_file: http://example.com/my_other_instance_user_data.sh

 

- get_attr : 특정 리소스의 속성 값을 가져오는 함수

            get_attr : [ 리소스ID, 속성명, 값 ] 

- get_file  : 파일을 불러오는 함수

- get_param : 파라미터(변수)를 가져와서 사용

            get_param [ 변수 이름, 값  ] 

- get_resource : 리소스 불러오는 함수 (동일한 탬플릿에서 정의한 다른 리소스의 값을 사용)

[root@controller ~(keystone_admin)]# pwd
/root
[root@controller ~(keystone_admin)]# vim .vimrc
[root@controller ~(keystone_admin)]# autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab autoindent
 # 줄여쓸 수 있음 'expandtab=et' 'autoindent=ai'
 
 [root@controller ~(keystone_admin)]# openstack server list
+--------------------------------------+------+---------+----------------------------------+-------+---------+
| ID                                   | Name | Status  | Networks                         | Image | Flavor  |
+--------------------------------------+------+---------+----------------------------------+-------+---------+
| c2529d3e-911c-4365-9445-058ef45b17a0 | 1vm  | SHUTOFF | 1netnet=192.168.56.15, 10.0.2.21 | 1mg   | 1flavor |
+--------------------------------------+------+---------+----------------------------------+-------+---------+
 
[root@controller ~(keystone_admin)]# export NET_ID=$(openstack network list |awk '/ 1netnet / { print $2 }')
[root@controller ~(keystone_admin)]# echo $NET_ID
5ef5acf8-321e-42a1-abc8-483b758a774b
[root@controller ~(keystone_admin)]# vim heat-stack.yml
heat_template_version : queens

description : First Heat Template

parameters :
  NetID :
    type : string
    description : Network ID for the server

resources :
  server :
    type : OS::Nova::Server
    properties :
      name : "Heat_Ubuntu16"
      image : 2mg
      flavor : m1.tiny
      networks :
      - network : { get_param : NetID }

outputs :
 server_ip :
   description : IP address of Instance from Provider network
   value : { get_attr : [ server, first_address ] }
   
   [root@controller ~(keystone_admin)]# openstack stack create -t heat-stack.yml --parameter "NetID=$NET_ID" stack1
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| id                  | 7df2863e-6cf1-406e-87b2-123dbaec171c |
| stack_name          | stack1                               |
| description         | First Heat Template                  |
| creation_time       | 2021-07-19T02:19:39Z                 |
| updated_time        | None                                 |
| stack_status        | CREATE_IN_PROGRESS                   |
| stack_status_reason | Stack CREATE started                 |
+---------------------+--------------------------------------+
[root@controller ~(keystone_admin)]# openstack stack delete stack1
Are you sure you want to delete this stack(s) [y/N]? y

 

인스턴스 생성

 ①main(GUI) > project > compute > instance > configuration > script or FILE  : gui 환경 서버 생성

 ②openstack server create --user-data 쉘스크립트, --file 설정파일 :  cli 환경 서버 생성

  ※ 간단한 변경으로 이미지나 인스턴스별 설정을 달리하는 것은 저장공간의 낭비이므로 cloud-init 사용

 cloud-init : 인스턴스의 초기 구성 작업을 진행

    ssh keypair 복사, 쉘스크립트 등을 실행      

    

[root@controller ~(keystone_admin)]# openstack stack create -t test.yml --wait st01
2021-07-21 00:34:18Z [st01]: CREATE_IN_PROGRESS  Stack CREATE started
2021-07-21 00:34:19Z [st01.create_sg]: CREATE_IN_PROGRESS  state changed
2021-07-21 00:34:20Z [st01.create_prinet]: CREATE_IN_PROGRESS  state changed
2021-07-21 00:34:20Z [st01.create_sg]: CREATE_COMPLETE  state changed
2021-07-21 00:34:21Z [st01.create_router]: CREATE_IN_PROGRESS  state changed
2021-07-21 00:34:21Z [st01.create_router]: CREATE_FAILED  StackValidationFailed: resources.create_router: Property error: Properties.external_gateway_info.network: Unable to find network with name or id 'template_pubnet'
2021-07-21 00:34:21Z [st01]: CREATE_FAILED  Resource CREATE failed: StackValidationFailed: resources.create_router: Property error: create_router.Properties.external_gateway_info.network: Unable to find network with name or id 'template_pubnet'
2021-07-21 00:34:21Z [st01.create_prinet]: CREATE_COMPLETE  state changed

 Stack st01 CREATE_FAILED 
 ### 라우터 때문에 failed 됐다. yml에는 문제가 없지만 재부팅이나 stack삭제후 재시도하였음.

[root@controller ~(keystone_admin)]# systemctl restart neutron-server
[root@controller ~(keystone_admin)]# openstack stack delete st01
Are you sure you want to delete this stack(s) [y/N]? yes
[root@controller ~(keystone_admin)]# openstack stack create -t test.yml --wait st01
2021-07-21 00:41:34Z [st01]: CREATE_IN_PROGRESS  Stack CREATE started
2021-07-21 00:41:35Z [st01.create_prinet]: CREATE_IN_PROGRESS  state changed
2021-07-21 00:41:36Z [st01.create_pubnet]: CREATE_IN_PROGRESS  state changed
2021-07-21 00:41:36Z [st01.create_prinet]: CREATE_COMPLETE  state changed
2021-07-21 00:41:36Z [st01.create_prisub]: CREATE_IN_PROGRESS  state changed
2021-07-21 00:41:37Z [st01.create_router]: CREATE_IN_PROGRESS  state changed
2021-07-21 00:41:37Z [st01.create_pubnet]: CREATE_COMPLETE  state changed
2021-07-21 00:41:37Z [st01.create_pubsub]: CREATE_IN_PROGRESS  state changed
2021-07-21 00:41:38Z [st01.create_sg]: CREATE_IN_PROGRESS  state changed
2021-07-21 00:41:41Z [st01.create_prisub]: CREATE_COMPLETE  state changed
2021-07-21 00:41:41Z [st01.create_server]: CREATE_IN_PROGRESS  state changed
2021-07-21 00:41:42Z [st01.create_router]: CREATE_COMPLETE  state changed
2021-07-21 00:41:42Z [st01.router_interface]: CREATE_IN_PROGRESS  state changed
2021-07-21 00:41:43Z [st01.create_sg]: CREATE_COMPLETE  state changed
2021-07-21 00:41:43Z [st01.create_port]: CREATE_IN_PROGRESS  state changed
2021-07-21 00:41:49Z [st01.router_interface]: CREATE_COMPLETE  state changed
2021-07-21 00:41:50Z [st01.create_pubsub]: CREATE_COMPLETE  state changed
2021-07-21 00:41:50Z [st01.create_port]: CREATE_COMPLETE  state changed
2021-07-21 00:41:50Z [st01.create_ip]: CREATE_IN_PROGRESS  state changed
2021-07-21 00:41:57Z [st01.create_ip]: CREATE_COMPLETE  state changed
2021-07-21 00:41:57Z [st01.association_ip]: CREATE_IN_PROGRESS  state changed
2021-07-21 00:42:00Z [st01.association_ip]: CREATE_COMPLETE  state changed
2021-07-21 00:42:06Z [st01.create_server]: CREATE_COMPLETE  state changed
2021-07-21 00:42:06Z [st01]: CREATE_COMPLETE  Stack CREATE completed successfully
+---------------------+-------------------------------------------------------------+
| Field               | Value                                                       |
+---------------------+-------------------------------------------------------------+
| id                  | a591160b-78b4-432a-85f3-b8bb230661c9                        |
| stack_name          | st01                                                        |
| description         | This is my first template This template is deploy instance. |
|                     |                                                             |
| creation_time       | 2021-07-21T00:41:34Z                                        |
| updated_time        | None                                                        |
| stack_status        | CREATE_COMPLETE                                             |
| stack_status_reason | Stack CREATE completed successfully                         |
+---------------------+-------------------------------------------------------------+
[root@controller ~(keystone_admin)]# openstack stack list
+--------------------------------------+------------+----------------------------------+-----------------+----------------------+--------------+
| ID                                   | Stack Name | Project                          | Stack Status    | Creation Time        | Updated Time |
+--------------------------------------+------------+----------------------------------+-----------------+----------------------+--------------+
| a591160b-78b4-432a-85f3-b8bb230661c9 | st01       | f21117852a8c4b8282852213e79b96c6 | CREATE_COMPLETE | 2021-07-21T00:41:34Z | None         |
+--------------------------------------+------------+----------------------------------+-----------------+----------------------+--------------+
[root@controller ~(keystone_admin)]# openstack server list
+--------------------------------------+-------------------+--------+-------------------------------+-------+---------+
| ID                                   | Name              | Status | Networks                      | Image | Flavor  |
+--------------------------------------+-------------------+--------+-------------------------------+-------+---------+
| 517abb5e-72f1-4afb-8cfe-e4ef12a4c924 | template_instance | ACTIVE | template_prinet=192.168.10.11 | 2mg   | m1.tiny |
+--------------------------------------+-------------------+--------+-------------------------------+-------+---------+
[root@controller ~(keystone_admin)]# openstack floating ip
create  delete  list    pool    set     show    unset
[root@controller ~(keystone_admin)]# openstack floating ip list
+--------------------------------------+---------------------+------------------+--------------------------------------+--------------------------------------+----------------------------------+
| ID                                   | Floating IP Address | Fixed IP Address | Port                                 | Floating Network                     | Project                          |
+--------------------------------------+---------------------+------------------+--------------------------------------+--------------------------------------+----------------------------------+
| 51a122a6-988b-4774-bf47-58814b0c5a70 | 10.0.2.20           | 192.168.10.25    | 9d47cf3d-6fe1-4383-bbd2-1e320da51c18 | cebaef21-0308-471b-ad31-2dd669794744 | f21117852a8c4b8282852213e79b96c6 |
+--------------------------------------+---------------------+------------------+--------------------------------------+--------------------------------------+----------------------------------+
[root@controller ~(keystone_admin)]#

 

 

 

[root@controller ~(keystone_admin)]# cat test.yml
heat_template_version : queens

description : >
   This is my first template
   This template is deploy instance.

parameters :
  PubNetID :
    type : string
    description : Network ID for Public
    default : template_pubnet
  PriNetID :
    type : string
    description : Network ID for Private
    default : template_prinet
  ImageID :
    type : string
    default : 2mg
  FlavorID :
    type : string
    default : m1.tiny
  KeyID :
    type : string
    default : 0713key
  SGID :
    type : string
    default : template_sg
  ServerID :
    type : string
    default : template_instance
  RouterID :
    type : string
    default : template_router


resources :
  create_server :
    type : OS::Nova::Server
    properties:
      name : { get_param : ServerID }
      flavor : { get_param : FlavorID }
      image : { get_param : ImageID }
      networks :
       - network : { get_resource : create_prinet }
      key_name : { get_param : KeyID }

  create_prinet :
    type : OS::Neutron::Net
    properties :
      name : { get_param : PriNetID }

  create_pubnet :
    type : OS::Neutron::ProviderNet
    properties :
      name : { get_param : PubNetID }
      network_type : flat
      physical_network : extnet
      router_external : true
      shared : true

  create_prisub :
    type : OS::Neutron::Subnet
    properties :
      name : tem_prisub
      network_id : { get_resource : create_prinet }
      cidr : 192.168.10.0/24


  create_pubsub :
    type : OS::Neutron::Subnet
    properties :
      name : pubsub
      network_id : { get_resource : create_pubnet }
      cidr : 10.0.2.0/24
      gateway_ip : 10.0.2.1
      allocation_pools :
       - start : 10.0.2.20
         end : 10.0.2.40
      enable_dhcp : false

  create_sg :
    type : OS::Neutron::SecurityGroup
    properties :
      name : { get_param : SGID }
      rules : [{"direction" : ingress, "port_range_max":22, "port_range_min":22, "protocol":tcp}, {"protocol":icmp}]

  create_router :
    type : OS::Neutron::Router
    properties :
      name : { get_param : RouterID }
      external_gateway_info :
        network : { get_param : PubNetID }

  router_interface :
    type : OS::Neutron::RouterInterface
    properties :
      router_id : { get_resource : create_router }
      subnet : { get_resource : create_prisub }

  create_port :
    type : OS::Neutron::Port
    properties :
      network_id : { get_resource : create_prinet }
      fixed_ips :
       - subnet_id : { get_resource : create_prisub }
      security_groups :
       - { get_resource : create_sg }

  create_ip :
    type : OS::Neutron::FloatingIP
    properties :
      floating_network : { get_resource : create_pubnet }
      port_id : { get_resource : create_port }

  association_ip :
    type : OS::Neutron::FloatingIPAssociation
    properties :
      floatingip_id : { get_resource : create_ip }
      port_id : { get_resource : create_port }

 

728x90

'openstack' 카테고리의 다른 글

20210723 (금) Manila  (0) 2021.07.23
20210716(금) 네트워크 실습  (0) 2021.07.16
20210714 (수) cinder 실습  (0) 2021.07.14
20210713 (화) ovs 브릿지  (0) 2021.07.13
20210713 (화) 리눅스 브릿지  (0) 2021.07.13
Comments