Skip to content

Instantly share code, notes, and snippets.

@karmab
Last active June 7, 2018 08:43
Show Gist options
  • Save karmab/e42630e4fb0788e9d594645a8a51295d to your computer and use it in GitHub Desktop.
Save karmab/e42630e4fb0788e9d594645a8a51295d to your computer and use it in GitHub Desktop.
kubevirt Packer image for google cloud compute
  • packer needs a patch pending from this pr
  • put the files except the json one in a kubevirt-button directory
  • edit packer-kubevirt-button.json to properly set the path of your account_file. You can optionally change things like
    • cpu and memory of the image with the machine_type
    • network_ip depending on which region you'll want the resulting images to launch in
  • create the image with the following command
packer build packer-kubevirt-button.json

then you can deploy an instance making sure you

  • name it kubevirt
  • force the primary private ip to 10.132.15.253
  • use the zone europe-west1-b ( to have the ip from the correct subnet)

to make the image available publicly, we need to store it in google cloud storage

PROJECT="kubevirt-button"
IMAGE="kubevirt-button"
VERSION="v0.5.0"
BUCKET="kubevirt"
gcloud compute images export --destination-uri gs://$BUCKET/$VERSION.tar.gz --image $IMAGE  --project $PROJECT
# Create the clusterrole and clusterrolebinding:
# $ kubectl create -f kube-flannel-rbac.yml
# Create the pod using the same namespace used by the flannel serviceaccount:
# $ kubectl create --namespace kube-system -f kube-flannel.yml
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: flannel
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- ""
resources:
- nodes
verbs:
- list
- watch
- apiGroups:
- ""
resources:
- nodes/status
verbs:
- patch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: flannel
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: flannel
subjects:
- kind: ServiceAccount
name: flannel
namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: flannel
namespace: kube-system
---
kind: ConfigMap
apiVersion: v1
metadata:
name: kube-flannel-cfg
namespace: kube-system
labels:
tier: node
app: flannel
data:
cni-conf.json: |
{
"name": "cbr0",
"type": "flannel",
"delegate": {
"isDefaultGateway": true
}
}
net-conf.json: |
{
"Network": "10.244.0.0/16",
"Backend": {
"Type": "vxlan"
}
}
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: kube-flannel-ds
namespace: kube-system
labels:
tier: node
app: flannel
spec:
template:
metadata:
labels:
tier: node
app: flannel
spec:
hostNetwork: true
nodeSelector:
beta.kubernetes.io/arch: amd64
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
serviceAccountName: flannel
containers:
- name: kube-flannel
image: quay.io/coreos/flannel:v0.7.1-amd64
command: [ "/opt/bin/flanneld", "--ip-masq", "--kube-subnet-mgr" ]
securityContext:
privileged: true
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
volumeMounts:
- name: run
mountPath: /run
- name: flannel-cfg
mountPath: /etc/kube-flannel/
- name: install-cni
image: quay.io/coreos/flannel:v0.7.1-amd64
command: [ "/bin/sh", "-c", "set -e -x; cp -f /etc/kube-flannel/cni-conf.json /etc/cni/net.d/10-flannel.conf; while true; do sleep 3600; done" ]
volumeMounts:
- name: cni
mountPath: /etc/cni/net.d
- name: flannel-cfg
mountPath: /etc/kube-flannel/
volumes:
- name: run
hostPath:
path: /run
- name: cni
hostPath:
path: /etc/cni/net.d
- name: flannel-cfg
configMap:
name: kube-flannel-cfg
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv001
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
nfs:
path: /pv001
server: kumaster
persistentVolumeReclaimPolicy: Recycle
{
"builders": [
{
"type": "googlecompute",
"account_file": "kubevirt-button-11642eb3792d.json",
"project_id": "kubevirt-button",
"source_image_family": "centos-7",
"disk_size": 50,
"image_description": "Kubevirt button",
"image_name": "kubevirt-button",
"instance_name": "kubevirt",
"machine_type": "custom-2-8192",
"network_ip": "10.132.15.253",
"ssh_username": "centos",
"zone": "europe-west1-b",
"image_licenses": ["projects/vm-options/global/licenses/enable-vmx"]
}
],
"provisioners": [
{
"type": "file",
"source": "kubevirt-button/deploy.sh",
"destination": "/home/centos/deploy.sh"
},
{
"type": "file",
"source": "kubevirt-button/kubernetes.repo",
"destination": "/home/centos/kubernetes.repo"
},
{
"type": "file",
"source": "kubevirt-button/kube-flannel-rbac.yml",
"destination": "/home/centos/kube-flannel-rbac.yml"
},
{
"type": "file",
"source": "kubevirt-button/kube-flannel.yml",
"destination": "/home/centos/kube-flannel.yml"
},
{
"type": "file",
"source": "kubevirt-button/kubernetes.repo",
"destination": "/home/centos/kubernetes.repo"
},
{
"type": "file",
"source": "kubevirt-button/nfs.yml",
"destination": "/home/centos/nfs.yml"
},
{
"type": "file",
"source": "kubevirt-button/vm.yml",
"destination": "/home/centos/vm.yml"
},
{
"type": "shell",
"inline": "sudo sh /home/centos/deploy.sh"
}
]
}
metadata:
name: testvm-ephemeral
apiVersion: kubevirt.io/v1alpha1
kind: VirtualMachine
spec:
domain:
resources:
requests:
memory: 64M
devices:
disks:
- name: registrydisk
volumeName: registryvolume
disk: {}
volumes:
- name: registryvolume
registryDisk:
image: kubevirt/alpine-registry-disk-demo:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment