Skip to content

Instantly share code, notes, and snippets.

@caleblloyd
Created January 29, 2016 18:45
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caleblloyd/4651e713689bfe43c74d to your computer and use it in GitHub Desktop.
Save caleblloyd/4651e713689bfe43c74d to your computer and use it in GitHub Desktop.
gcloud compute instances create nfs \
--image container-vm \
--metadata-from-file startup-script=privileged.sh,google-container-manifest=nfs-vm-config.yaml \
--zone us-central1-c \
--scopes storage-ro,useraccounts-ro,logging-write,compute-rw \
--machine-type n1-standard-1

Google Compute Engine NFS Container VM

This script creates a Container VM on Google Compute Engine running a NFS V4 server exposed on Port 2049 with the /exports directory mounted to a persistent disk. This means:

  • If the NFS VM Crashes, the persistent disk will still hold the NFS Files
  • The persistent disk can be snapshotted to backup NFS Files

To run:

  1. Install the Google Cloud SDK and authenticate to your project: https://cloud.google.com/sdk/
  2. Create a Persistent Disk named "nfs-pd"
  3. Download the files create.sh, nfs-vm-config.yaml, and privileged.sh to the same folder
  4. Run the create.sh script

To connect:

Use a NFS V4 client on other Compute Engine instances to connect to your NFS VM. You can use the NFS VM name ("nfs" in this script) as the hostame in order to resolve to the NFS VM's internal IP Address.

To debug:

  1. SSH to the container vm
  2. Execute "sudo docker ps". You should see the nfs container running. If you don't, check out the logs in /var/log/kubelet.log
apiVersion: v1
kind: Pod
metadata:
name: nfs
spec:
containers:
- name: nfs
image: gcr.io/google_containers/volume-nfs
imagePullPolicy: Always
ports:
- name: nfs
containerPort: 2049
hostPort: 2049
volumeMounts:
- mountPath: /exports
name: nfs-pd
securityContext:
privileged: true
volumes:
- name: nfs-pd
gcePersistentDisk:
pdName: nfs-pd
fsType: ext4
#!/bin/bash
sed -i 's/DAEMON_ARGS="/DAEMON_ARGS="--allow-privileged=true /g' /etc/default/kubelet
service kubelet restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment