Last active
July 5, 2020 11:05
-
-
Save ralvares/be6ca31455ec11e6e53938c5f3b871f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Create an Container Image with centos8 qcow2 | |
oc new-build --name centos8 --build-arg image_url=https://cloud.centos.org/centos/8/x86_64/images/CentOS-8-GenericCloud-8.1.1911-20200113.3.x86_64.qcow2 https://github.com/openshift-examples/cnv-container-disk-build.git | |
#Create Openshift Template | |
cat > apache-template.yaml << EOF | |
# Source: dist/templates/centos8-server-tiny.yaml | |
apiVersion: template.openshift.io/v1 | |
kind: Template | |
metadata: | |
name: apache-centos8-server-tiny | |
annotations: | |
openshift.io/display-name: "Demo CNV VM - Apache webserver" | |
description: >- | |
This template can be used to create a VM suitable for | |
CentOS 8 and newer. | |
The template assumes that a Container Image is available which is providing the | |
necessary CentOS disk image. | |
tags: "kubevirt,virtualmachine,linux,centos" | |
iconClass: "icon-centos" | |
openshift.io/provider-display-name: "KubeVirt" | |
openshift.io/documentation-url: "https://github.com/kubevirt/common-templates" | |
openshift.io/support-url: "https://github.com/kubevirt/common-templates/issues" | |
template.openshift.io/bindable: "true" | |
template.kubevirt.io/version: v1alpha1 | |
defaults.template.kubevirt.io/disk: rootdisk | |
template.kubevirt.io/editable: | | |
/objects[0].spec.template.spec.domain.cpu.sockets | |
/objects[0].spec.template.spec.domain.cpu.cores | |
/objects[0].spec.template.spec.domain.cpu.threads | |
/objects[0].spec.template.spec.domain.resources.requests.memory | |
/objects[0].spec.template.spec.domain.devices.disks | |
/objects[0].spec.template.spec.volumes | |
/objects[0].spec.template.spec.networks | |
name.os.template.kubevirt.io/centos8.0: CentOS 8.0 | |
labels: | |
os.template.kubevirt.io/centos8.0: "true" | |
workload.template.kubevirt.io/server: "true" | |
flavor.template.kubevirt.io/tiny: "true" | |
template.kubevirt.io/type: "base" | |
objects: | |
- kind: Route | |
apiVersion: route.openshift.io/v1 | |
metadata: | |
name: ${NAME} | |
spec: | |
to: | |
kind: Service | |
name: ${NAME} | |
weight: 100 | |
port: | |
targetPort: 80 | |
wildcardPolicy: None | |
- kind: Service | |
apiVersion: v1 | |
metadata: | |
name: ${NAME} | |
spec: | |
ports: | |
- protocol: TCP | |
port: 80 | |
targetPort: 80 | |
selector: | |
vm.kubevirt.io/name: ${NAME} | |
type: ClusterIP | |
sessionAffinity: None | |
- apiVersion: kubevirt.io/v1alpha3 | |
kind: VirtualMachine | |
metadata: | |
name: ${NAME} | |
labels: | |
vm.kubevirt.io/template: apache-centos8-server-tiny | |
vm.kubevirt.io/name: ${NAME} | |
app: ${NAME} | |
spec: | |
running: true | |
template: | |
metadata: | |
labels: | |
kubevirt.io/domain: ${NAME} | |
vm.kubevirt.io/name: ${NAME} | |
kubevirt.io/size: tiny | |
spec: | |
domain: | |
cpu: | |
sockets: 1 | |
cores: 1 | |
threads: 1 | |
resources: | |
requests: | |
memory: 1G | |
devices: | |
rng: {} | |
disks: | |
- disk: | |
bus: virtio | |
name: rootdisk | |
- disk: | |
bus: virtio | |
name: cloudinitdisk | |
interfaces: | |
- bridge: {} | |
name: default | |
terminationGracePeriodSeconds: 0 | |
networks: | |
- name: default | |
pod: {} | |
volumes: | |
- containerDisk: | |
image: 'image-registry.openshift-image-registry.svc:5000/kubevirt/centos8' | |
name: rootdisk | |
- cloudInitNoCloud: | |
userData: |- | |
#cloud-config | |
password: centos | |
chpasswd: { expire: False } | |
packages: | |
- httpd | |
- mod_php | |
- php-mbstring | |
- php-mysqlnd | |
- php-json | |
- php-xml | |
- libxslt | |
- mariadb | |
runcmd: | |
- [ systemctl, enable, httpd.service ] | |
- [ systemctl, start, httpd.service ] | |
- curl https://wordpress.org/latest.tar.gz --output /tmp/wordpress.tar.gz | |
- tar xf /tmp/wordpress.tar.gz -C /var/www/html/ | |
- chown -R apache:apache /var/www/html/wordpress | |
- chcon -t httpd_sys_rw_content_t /var/www/html/wordpress -R | |
- setsebool -P httpd_can_network_connect_db on | |
name: cloudinitdisk | |
parameters: | |
- description: VM name | |
from: 'centos8-[a-z0-9]{16}' | |
generate: expression | |
name: NAME | |
required: true | |
EOF | |
oc apply -f apache-template.yaml | |
Using the console ( mode developer ) - create a application based on the catalog ( Search for demo ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment