小编Col*_*rk1的帖子

CloudFormation 资源创建(如果不存在)

我想用 CloudFormation 创建 Route53 HostedZone,所以我想检查一下 Route53 中关于 HostedZone 的一些信息是否存在。

在我的情况下,我需要检查资源是否存在,忽略资源创建。我该如何处理这个问题。

我的 CloudFormation 模板如下所示。

"myDNSRecord" : {
  "Type" : "AWS::Route53::RecordSet",
  "Properties" : {
    "HostedZoneName" : { "Ref" : "HostedZoneResource" },
    "Comment" : "DNS name for my instance.",  
    "Name" : {
      "Fn::Join" : [ "", [
        {"Ref" : "Ec2Instance"}, ".",
        {"Ref" : "AWS::Region"}, ".",
        {"Ref" : "HostedZone"} ,"."
      ] ]
    },
    "Type" : "A",
    "TTL" : "900",
    "ResourceRecords" : [
      { "Fn::GetAtt" : [ "Ec2Instance", "PublicIp" ] }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-cloudformation devops infrastructure-as-code

13
推荐指数
1
解决办法
1万
查看次数

AWS CloudFormation UserData EC2 环境变量

我正在使用 CloudFormation 开发基础设施。这是我自己的基础架构代码,如下所示。

 AWSRegionArch2AMI:
     us-east-1:
       HVM64: ami-0ff8a91507f77f867
       HVMG2: ami-0a584ac55a7631c0c
 ...
 ..
 .

 Resources:
 EC2Instance:
 Type: AWS::EC2::Instance
 Properties:
 InstanceType:
    Ref: InstanceType
  SecurityGroups:
  - Ref: InstanceSecurityGroup
  KeyName:
    Ref: KeyName
  UserData:
    Fn::Base64: !Sub |
      #!/bin/bash
      export MY_AMI_NAME=${ !GetAtt AWSRegionArch2AMI.us-east-1.HVM64 }

      echo $MY_AMI_NAME > $HOME/user_data.txt
Run Code Online (Sandbox Code Playgroud)

我想将变量设置为 user_data 文件,但它是空的,如何将环境变量放入我的用户数据字段中并在我自己的应用程序端使用它我该怎么做。

请帮忙 !

amazon-web-services aws-cloudformation

7
推荐指数
1
解决办法
3932
查看次数

Kubernetes Ingress网络拒绝某些路径

我有一个简单的kubernetes入口网络。

我需要拒绝访问一些关键路径,例如/ admin或其他。

我的入口网络文件如下所示。

 apiVersion: extensions/v1beta1
 kind: Ingress
 metadata:
 name: ingress-test
 spec:
   rules:
   - host: host.host.com
   http:
      paths:
        - path: /service-mapping
      backend:
         serviceName: /service-mapping
         servicePort: 9042
Run Code Online (Sandbox Code Playgroud)

如何使用kubernetes入口网络,nginx注释或其他方法拒绝自定义路径。


我通过如下所示的注释来处理此问题。

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
   name: nginx-configuration-snippet
   annotations:
      nginx.ingress.kubernetes.io/configuration-snippet: |

     server_tokens off;
     location DANGER-PATH {
    deny all;
    return 403;
  }

spec:
  rules:
   - host: api.myhost.com
   http:
  paths:
  - backend:
      serviceName: bookapi-2
      servicePort: 8080
    path: PATH 
Run Code Online (Sandbox Code Playgroud)

nginx kubernetes kubernetes-ingress

5
推荐指数
3
解决办法
3134
查看次数

Kubernetes跨命名空间入口网络

我有一个简单的入口网络,我想从该入口网络访问不同名称空间的服务。

我该怎么做?我的入口网络yaml文件:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
spec:
  rules:
 - host: api.myhost.com
 http:
 paths:
  - backend:
      serviceName: bookapi-2
      servicePort: 8080
    path: /booking-service/
Run Code Online (Sandbox Code Playgroud)

我已经将ExternalNames服务类型设置为yaml文件:

 apiVersion: v1
 kind: Service
 metadata:
   name: bookapi-2
   namespace: booking-namespace
 spec:
   type: ExternalName
   externalName: bookapi-2
   ports:
     - name: app
     protocol: TCP
      port: 8080
      targetPort: 8080
   selector:
      app: bookapi-2
      tier: backend-2
Run Code Online (Sandbox Code Playgroud)

kubernetes microservices kubernetes-ingress

3
推荐指数
2
解决办法
6406
查看次数

Terraform 嵌套模块调用和输出

我正在处理基础设施配置,所以我将模块称为嵌套。

有我的文件系统树。

   ??? main.tf
   ??? modules
       ??? client.tf
       ??? in
          ??? main.tf
Run Code Online (Sandbox Code Playgroud)

我的文件显示如下。

   #main.tf 
   module "my_vpc" {
          source = "./modules"
   }

   # modules/client.tf
   provider "aws" {
          region = "us-east-2"
   }

   module "inner" {
          source = "./in"
   }

  # in/main.tf

  provider "aws" {
        region = "us-east-2"
  }

  resource "aws_vpc" "main" {
        cidr_block = "10.0.0.0/16"
  }

  output "vpc_id" {
      value = "${aws_vpc.main.id}"
  }
Run Code Online (Sandbox Code Playgroud)

所以就我而言,我想从 in/main.tf 中的资源创建模块中获取输出。但是当我运行 terraform apply 命令时,没有输出。

我该如何解决这个问题?

amazon-web-services terraform devops infrastructure-as-code

2
推荐指数
1
解决办法
8607
查看次数

Cloudformation Init 的 Cloudformation 输出

我有一个 CloudFormation 堆栈,如下所示,

  "Metadata" : {
            "AWS::CloudFormation::Init" : {
                "config" : {

                        "/home/ec2-user/create_db_user.sh" : {
                            "source" :                             

   "http://s3.amazonaws.com/devops/create_db_user.sh",
                            "mode" : "000755",
                            "owner" : "ec2-user"
                        }
                    }
 ...
Run Code Online (Sandbox Code Playgroud)

在我需要将此初始化脚本输出设置为 cloudformation 堆栈之后,我需要在 EC2 实例启动时运行此命令。

我怎么能这样。

amazon-web-services aws-cloudformation devops infrastructure-as-code

1
推荐指数
1
解决办法
2068
查看次数