Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction pratique à CoreOS et Terraform

Introduction pratique à CoreOS et Terraform

Présentation par la pratique de CoreOS et Terraform, du point de vue développeur.
HumanTalks Grenoble du 08/11/2016

Ba2198386e326d6e3ca57b2271d861e9?s=128

Yves Brissaud

November 08, 2016
Tweet

Transcript

  1. Yves.Brissaud @sogilis.com
 @SquareScale.com @_crev_
 eunomie Introduction Pratique
 à CoreOS et

    Terraform Pour les développeurs Human Talks Grenoble
 08/11/2016
  2. Introduction Pratique Par l’exemple

  3. Problème ?

  4. Problème ?

  5. Problème ?

  6. Problème ? ❓

  7. None
  8. Besoin Installer ElasticSearch (

  9. Besoin Installer ElasticSearch ( ❓ ❓

  10. https://www.elastic.co/guide/en/elasticsearch/reference/current/_installation.html

  11. https://www.elastic.co/guide/en/elasticsearch/reference/current/_installation.html $ curl -L -O https://artifacts.elastic.co/ downloads/elasticsearch/ elasticsearch-5.0.0.tar.gz $ tar

    -xvf elasticsearch-5.0.0.tar.gz $ cd elasticsearch-5.0.0/bin $ ./elasticsearch
  12. $ curl -L -O https://artifacts.elastic.co/ downloads/elasticsearch/ elasticsearch-5.0.0.tar.gz $ tar -xvf

    elasticsearch-5.0.0.tar.gz $ cd elasticsearch-5.0.0/bin $ ./elasticsearch https://www.elastic.co/guide/en/elasticsearch/reference/current/_installation.html
  13. $ curl -L -O https://artifacts.elastic.co/ downloads/elasticsearch/ elasticsearch-5.0.0.tar.gz $ tar -xvf

    elasticsearch-5.0.0.tar.gz $ cd elasticsearch-5.0.0/bin $ ./elasticsearch https://www.elastic.co/guide/en/elasticsearch/reference/current/_installation.html ❓ Où ?
  14. $ curl -L -O https://artifacts.elastic.co/ downloads/elasticsearch/ elasticsearch-5.0.0.tar.gz $ tar -xvf

    elasticsearch-5.0.0.tar.gz $ cd elasticsearch-5.0.0/bin $ ./elasticsearch https://www.elastic.co/guide/en/elasticsearch/reference/current/_installation.html ❓ ❓ Répétabilité ?
  15. $ curl -L -O https://artifacts.elastic.co/ downloads/elasticsearch/ elasticsearch-5.0.0.tar.gz $ tar -xvf

    elasticsearch-5.0.0.tar.gz $ cd elasticsearch-5.0.0/bin $ ./elasticsearch https://www.elastic.co/guide/en/elasticsearch/reference/current/_installation.html ❓ ❓ ❓ Scale ?
  16. $ curl -L -O https://artifacts.elastic.co/ downloads/elasticsearch/ elasticsearch-5.0.0.tar.gz $ tar -xvf

    elasticsearch-5.0.0.tar.gz $ cd elasticsearch-5.0.0/bin $ ./elasticsearch https://www.elastic.co/guide/en/elasticsearch/reference/current/_installation.html ❓ ❓ ❓ ❓ Documentation ?
  17. Quelles solutions ? - Infrastructure - Applicatif

  18. Quelles solutions ? - Infrastructure - Applicatif

  19. Terraform.io WRITE, PLAN, AND CREATE INFRASTRUCTURE AS CODE

  20. (/ resource "aws_instance" "elasticsearch" { }

  21. (/ resource "aws_instance" "elasticsearch" { } Type de ressource :


    Instance Amazon Web Service (EC2)
  22. (/ resource "aws_instance" "elasticsearch" { } Nom de la ressource

  23. (/ resource "aws_instance" "elasticsearch" { instance_type = "t2.micro" } Instance

    Amazon Web Service (EC2)
 Taille : t2.micro -> 1 vCPU, 1Go RAM
  24. (/ resource "aws_instance" "elasticsearch" { instance_type = "t2.micro" ami =

    "ami-7ddc960e" } Amazon Machine Image
  25. (/ resource "aws_instance" "elasticsearch" { instance_type = "t2.micro" ami =

    "ami-7ddc960e" } CoreOS 1185.3.0
  26. (/ resource "aws_instance" "elasticsearch" { instance_type = "t2.micro" ami =

    "ami-7ddc960e" associate_public_ip_address = true }
  27. (/ resource "aws_instance" "elasticsearch" { instance_type = "t2.micro" ami =

    "ami-7ddc960e" associate_public_ip_address = true subnet_id = "subnet-6f6f2919" } Réseau local
  28. (/ resource "aws_instance" "elasticsearch" { instance_type = "t2.micro" ami =

    "ami-7ddc960e" associate_public_ip_address = true subnet_id = "subnet-6f6f2919" vpc_security_group_ids = ["${aws_security_group.base_sg.id}"] } ± Firewall
  29. (/ resource "aws_instance" "elasticsearch" { instance_type = "t2.micro" ami =

    "ami-7ddc960e" associate_public_ip_address = true subnet_id = "subnet-6f6f2919" vpc_security_group_ids = ["${aws_security_group.base_sg.id}"] } Port 22 + Ping + sortie
  30. (/ resource "aws_instance" "elasticsearch" { instance_type = "t2.micro" ami =

    "ami-7ddc960e" associate_public_ip_address = true subnet_id = "subnet-6f6f2919" vpc_security_group_ids = ["${aws_security_group.base_sg.id}"] key_name = "${aws_key_pair.admin_key.key_name}" } Clé SSH
  31. (/ resource "aws_instance" "elasticsearch" { instance_type = "t2.micro" ami =

    "ami-7ddc960e" associate_public_ip_address = true subnet_id = "subnet-6f6f2919" vpc_security_group_ids = ["${aws_security_group.base_sg.id}"] key_name = "${aws_key_pair.admin_key.key_name}" }
  32. None
  33. Quelles solutions ? - Infrastructure - Applicatif

  34. Quelles solutions ? - Infrastructure - Applicatif

  35. Quelles solutions ? - Infrastructure - Applicatif

  36. https://www.elastic.co/guide/en/elasticsearch/reference/current/_installation.html $ curl -L -O https://artifacts.elastic.co/ downloads/elasticsearch/ elasticsearch-5.0.0.tar.gz $ tar

    -xvf elasticsearch-5.0.0.tar.gz $ cd elasticsearch-5.0.0/bin $ ./elasticsearch
  37. https://www.elastic.co/guide/en/elasticsearch/reference/current/_installation.html $ curl -L -O https://artifacts.elastic.co/ downloads/elasticsearch/ elasticsearch-5.0.0.tar.gz $ tar

    -xvf elasticsearch-5.0.0.tar.gz $ cd elasticsearch-5.0.0/bin $ ./elasticsearch
  38. https://store.docker.com/images/1090e442-627e-4bf2-b29a-555f57a64ecd

  39. https://store.docker.com/images/1090e442-627e-4bf2-b29a-555f57a64ecd $ docker run -d elasticsearch

  40. None
  41. None
  42. None
  43. CoreOS.com

  44. CoreOS.com Distribution Linux légère

  45. CoreOS.com Distribution Linux légère Pas de gestionnaire de paquet

  46. CoreOS.com Distribution Linux légère Pas de gestionnaire de paquet Cluster

  47. CoreOS.com Distribution Linux légère Pas de gestionnaire de paquet Cluster

    Containers
  48. CoreOS - Terraform

  49. CoreOS - Terraform resource "aws_instance" "elasticsearch" { instance_type = "t2.micro"

    ami = "ami-7ddc960e" associate_public_ip_address = true subnet_id = "subnet-6f6f2919" vpc_security_group_ids = ["${aws_security_group.base_sg.id}"] key_name = "${aws_key_pair.admin_key.key_name}" }
  50. CoreOS - Terraform resource "aws_instance" "elasticsearch" { instance_type = "t2.micro"

    ami = "ami-7ddc960e" associate_public_ip_address = true subnet_id = "subnet-6f6f2919" vpc_security_group_ids = ["${aws_security_group.base_sg.id}"] key_name = "${aws_key_pair.admin_key.key_name}" user_data = "${file("cloud-config/elasticsearch.yml")}" }
  51. CoreOS - Terraform #cloud-config


  52. CoreOS - Terraform #cloud-config
 Header (autre choix : #! pour

    shell)
  53. CoreOS - Terraform #cloud-config
 coreos:
 units: Ensemble d’units Systemd

  54. CoreOS - Terraform #cloud-config
 coreos:
 units:
 - name: elasticsearch.service
 command:

    start
 content: |
  55. CoreOS - Terraform #cloud-config
 coreos:
 units:
 - name: elasticsearch.service
 command:

    start
 content: |
 [Unit]
 Description=Elastic Search
  56. CoreOS - Terraform #cloud-config
 coreos:
 units:
 - name: elasticsearch.service
 command:

    start
 content: |
 [Unit]
 Description=Elastic Search
 After=docker.service
 Requires=docker.service
  57. CoreOS - Terraform #cloud-config
 coreos:
 units:
 - name: elasticsearch.service
 command:

    start
 content: |
 [Unit]
 Description=Elastic Search
 After=docker.service
 Requires=docker.service
 [Service]
 Restart=always
  58. CoreOS - Terraform #cloud-config
 coreos:
 units:
 - name: elasticsearch.service
 command:

    start
 content: |
 [Unit]
 Description=Elastic Search
 After=docker.service
 Requires=docker.service
 [Service]
 Restart=always
 ExecStartPre=-/usr/bin/docker kill elasticsearch
 ExecStartPre=-/usr/bin/docker pull elasticsearch:2.4

  59. CoreOS - Terraform #cloud-config
 coreos:
 units:
 - name: elasticsearch.service
 command:

    start
 content: |
 [Unit]
 Description=Elastic Search
 After=docker.service
 Requires=docker.service
 [Service]
 Restart=always
 ExecStartPre=-/usr/bin/docker kill elasticsearch
 ExecStartPre=-/usr/bin/docker pull elasticsearch:2.4
 ExecStart=/usr/bin/docker run --rm --hostname elasticsearch
 --name elasticsearch -p 9200:9200 elasticsearch:2.4

  60. CoreOS - Terraform #cloud-config
 coreos:
 units:
 - name: elasticsearch.service
 command:

    start
 content: |
 [Unit]
 Description=Elastic Search
 After=docker.service
 Requires=docker.service
 [Service]
 Restart=always
 ExecStartPre=-/usr/bin/docker kill elasticsearch
 ExecStartPre=-/usr/bin/docker pull elasticsearch:2.4
 ExecStart=/usr/bin/docker run --rm --hostname elasticsearch
 --name elasticsearch -p 9200:9200 elasticsearch:2.4
 ExecStop=/usr/bin/docker stop elasticsearch
  61. CoreOS - Terraform resource "aws_instance" "elasticsearch" { instance_type = "t2.micro"

    ami = "ami-7ddc960e" associate_public_ip_address = true subnet_id = "subnet-6f6f2919" vpc_security_group_ids = ["${aws_security_group.base_sg.id}"]
 key_name = "${aws_key_pair.admin_key.key_name}" user_data = "${file("cloud-config/elasticsearch.yml")}" }
  62. CoreOS - Terraform resource "aws_instance" "elasticsearch" { instance_type = "t2.micro"

    ami = "ami-7ddc960e" associate_public_ip_address = true subnet_id = "subnet-6f6f2919" vpc_security_group_ids = ["${aws_security_group.base_sg.id}",
 "${aws_security_group.elasticsearch_sg.id}"] key_name = "${aws_key_pair.admin_key.key_name}" user_data = "${file("cloud-config/elasticsearch.yml")}" } Port 9200
  63. None
  64. Quelles solutions ? - Infrastructure - Applicatif

  65. Quelles solutions ? - Infrastructure - Applicatif

  66. Quelles solutions ? - Infrastructure - Applicatif

  67. Quelles solutions ? - Infrastructure - Applicatif Doc : Code

  68. Quelles solutions ? - Infrastructure - Applicatif Répétable

  69. Quelles solutions ? - Infrastructure - Applicatif Serveur géré

  70. Quelles solutions ? - Infrastructure - Applicatif Configurable

  71. resource "aws_instance" "elasticsearch" {
 instance_type = "t2.micro"
 ami = "ami-7ddc960e"


    associate_public_ip_address = true
 subnet_id = "subnet-6f6f2919"
 vpc_security_group_ids =
 ["${aws_security_group.base_sg.id}",
 "${aws_security_group.elasticsearch_sg.id}"]
 key_name =
 "${aws_key_pair.admin_key.key_name}"
 user_data =
 "${file("cloud-config/elasticsearch.yml")}"
 }
 resource "aws_security_group" "base_sg" {
 name = "base_sg"
 vpc_id = "vpc-b89ee9dc"
 ingress {
 from_port = 22
 to_port = 22
 protocol = "tcp"
 cidr_blocks = ["0.0.0.0/0"]
 }
 ingress {
 from_port = 8
 to_port = -1
 protocol = "icmp"
 cidr_blocks = ["0.0.0.0/0"]
 }
 egress {
 from_port = 0
 to_port = 0
 protocol = "-1"
 cidr_blocks = ["0.0.0.0/0"]
 }
 }
 resource "aws_security_group" "elasticsearch_sg" {
 name = "elasticsearch_sg"
 vpc_id = "vpc-b89ee9dc"
 ingress {
 from_port = 9200
 to_port = 9200
 protocol = "tcp"
 cidr_blocks = ["0.0.0.0/0"]
 }
 } #cloud-config
 coreos:
 units:
 - name: elasticsearch.service
 command: start
 content: |
 [Unit]
 Description=Elastic Search
 After=docker.service
 Requires=docker.service
 [Service]
 Restart=always
 ExecStartPre=-/usr/bin/docker kill elasticsearch
 ExecStartPre=-/usr/bin/docker pull elasticsearch:2.4
 ExecStart=/usr/bin/docker run --rm -- hostname elasticsearch --name elasticsearch -p 9200:9200 elasticsearch:2.4
 ExecStop=/usr/bin/docker stop elasticsearch variable "aws_access_key" {}
 variable "aws_secret_key" {}
 variable "aws_region" {
 default = "eu-west-1"
 }
 provider "aws" {
 access_key = "${var.aws_access_key}"
 secret_key = "${var.aws_secret_key}"
 region = "${var.aws_region}"
 }
  72. #cloud-config
 coreos:
 units:
 - name: elasticsearch.service
 command: start
 content: |


    [Unit]
 Description=Elastic Search
 After=docker.service
 Requires=docker.service
 [Service]
 Restart=always
 ExecStartPre=-/usr/bin/docker kill elasticsearch
 ExecStartPre=-/usr/bin/docker pull elasticsearch:2.4
 ExecStart=/usr/bin/docker run --rm -- hostname elasticsearch --name elasticsearch -p 9200:9200 elasticsearch:2.4
 ExecStop=/usr/bin/docker stop elasticsearch variable "aws_access_key" {}
 variable "aws_secret_key" {}
 variable "aws_region" {
 default = "eu-west-1"
 }
 provider "aws" {
 access_key = "${var.aws_access_key}"
 secret_key = "${var.aws_secret_key}"
 region = "${var.aws_region}"
 } ❓ resource "aws_instance" "elasticsearch" {
 instance_type = "t2.micro"
 ami = "ami-7ddc960e"
 associate_public_ip_address = true
 subnet_id = "subnet-6f6f2919"
 vpc_security_group_ids =
 ["${aws_security_group.base_sg.id}",
 "${aws_security_group.elasticsearch_sg.id}"]
 key_name =
 "${aws_key_pair.admin_key.key_name}"
 user_data =
 "${file("cloud-config/elasticsearch.yml")}"
 }
 resource "aws_security_group" "base_sg" {
 name = "base_sg"
 vpc_id = "vpc-b89ee9dc"
 ingress {
 from_port = 22
 to_port = 22
 protocol = "tcp"
 cidr_blocks = ["0.0.0.0/0"]
 }
 ingress {
 from_port = 8
 to_port = -1
 protocol = "icmp"
 cidr_blocks = ["0.0.0.0/0"]
 }
 egress {
 from_port = 0
 to_port = 0
 protocol = "-1"
 cidr_blocks = ["0.0.0.0/0"]
 }
 }
 resource "aws_security_group" "elasticsearch_sg" {
 name = "elasticsearch_sg"
 vpc_id = "vpc-b89ee9dc"
 ingress {
 from_port = 9200
 to_port = 9200
 protocol = "tcp"
 cidr_blocks = ["0.0.0.0/0"]
 }
 }
  73. terraform.io coreos.com speakerdeck.com/eunomie github.com/eunomie