0

I am trying to deploy a Linux VM with tag "http" and creating firewall for allowing HTTP Port 80 access as tagged firewall "http". The VM is getting deployed but no external access is working for the VM. Also gave startup script for VM but its not working

resources:
- type: compute.v1.instance
  name: vm-test
  properties:
    metadata:
      items:
      - key: startup-script-url
        value: https://storage.googleapis.com/cf405bucket/install-web.sh
    zone: {{ properties["zone"] }}
    machineType: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/zones/{{ properties["zone"] }}/machineTypes/n1-standard-2
    # For examples on how to use startup scripts on an instance, see:
    #   https://cloud.google.com/compute/docs/startupscript
    tags:
      items: ["http"]
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        diskName: disk-{{ env["deployment"] }}
        sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-9
    networkInterfaces:
    - network: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/global/networks/default
      # Access Config required to give the instance a public IP address
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT
- type: compute.v1.firewall
  name: default-allow-http
  properties:
    sourceRanges: ["0.0.0.0/0"]
    network: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/global/networks/default 
    targetTags: ["http"]
    allowed:
    - IPProtocol: TCP
      ports: ["80"]
mle
  • 2,466
  • 1
  • 19
  • 25
Kunal
  • 1
  • Is your server listening on port 80? All we can see here is that you deployed an instance that you should be able to reach on port 80, not that you installed something that make your server listen on port 80 like nginx or apache. – night-gold May 07 '19 at 14:16
  • Hi. I am trying to install apache using startup script in VM. That would be listening to port 80. – Kunal May 07 '19 at 14:59
  • Are you sure it's working? To if the serveur is listening to 0.0.0.0:* log onto the server and do this command: netstat -tlupn – night-gold May 07 '19 at 15:38
  • Post your startup script. Look at the Stackdriver logs for this instance and review the error messages. You can also look and the Compute Engine console output. – John Hanley May 07 '19 at 17:45
  • The start script is #!/bin/bash apt-get update apt-get install -y apache2 cat < /var/www/html/index.html

    Hello World

    This page was created from a simple startup script!

    EOF service apache2 start
    – Kunal May 08 '19 at 04:48
  • Post your script formatted in your question. How can we detect errors from putting the script as a blob in a comment? – John Hanley May 08 '19 at 06:34

1 Answers1

0

Try SSH'ing into the deployment's created VM instance and run the command apache2 --version.

What happens? I assume you'll be told it isn't a recognised command or something...given it looks like the web server hasn't been installed for some reason. If so, perhaps try updating install-web.sh to include sudo before commands, i.e.,

#!/bin/bash
sudo apt-get update
sudo apt-get install -y apache2

Failing that, why not ditch the install-web.sh file altogether and just include the script in the config file directly (as there isn't much to it), e.g., something like:

    metadata:
     items:
     - key: startup-script
       value: |
          #!/bin/bash
          apt-get update
          apt-get install -y apache2
Scott
  • 1,208
  • 9
  • 28