Skip to content

Instantly share code, notes, and snippets.

@goern
Last active October 31, 2017 08:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goern/d21e5f9bee733a4f30c7 to your computer and use it in GitHub Desktop.
Save goern/d21e5f9bee733a4f30c7 to your computer and use it in GitHub Desktop.
Atomic Host demo on Google Compute Engine (GCE)

Overview

Basically four steps:

  1. install SDK and initialize a new project via console
  2. upload and generate a new GCE image for your project
  3. instantiate a new instance on GCE using the image
  4. follow a known path

install SDK and initialize a new project via console

  • Sign up for Google Compute Engine
  • Download and install the Cloud SDK
  • Authenticate your client
  • Set your project ID - "A project ID is the customized name you chose when you created the project, or when you activated an API that required you to create a project ID. It can be found in the Dashboard of the project ... ", see GCE doc

That's it for the first step...

upload and generate a new GCE image for your project

download and prepare Atomic Host image

download the current cloud image of Atomic Host and store it in your project directory.

cd <project-dir>
curl <URL of Atomic Host> -o rhel-atomic-host-cloud.qcow2.xz

convert

Convert the Atomic Host qcow2 to a raw file and package it with tar

xz --decompress rhel-atomic-host-cloud.qcow2.xz
qemu-img convert -S 4096 -f qcow2 -O raw rhel-atomic-host-cloud.qcow2 disk.raw
tar -Szcf rhel-atomic-host-image.tar.gz disk.raw

publish (upload) the tar

Upload the tar file into a Google Storage bucket.

gsutil mb gs://<bucket-name>
gsutil cp rhel-atomic-host-image.tar.gz gs://<bucket-name>

convert

After upload, the tar file is converted to a GCE image.

gcloud compute images create rhel-7-atomic-host --source-uri gs://<bucket-name>/rhel-atomic-host-image.tar.gz
gcloud compute images list

Done.

instantiate a new instance on GCE using the image

gcutil addinstance <project-name>-instance --machine_type=n1-standard-1 --image=rhel-7-atomic-host --zone=europe-west1-a --wait_until_running --auto_delete_boot_disk
gcloud compute ssh cloud-user@<project-name>-instance --zone europe-west1-a

This is it, you should be on a fresh Atomic Host on Google Compute Engine.

follow a known path

After logging in, use your new Atomic Host. Don't forget to open up the firewall

gcloud compute firewall-rules create allow-http --description "Incoming http allowed." --allow tcp:80

start all Kubernetes Services and pull your docker images, or build a new one on the host...

sudo systemctl start etcd.service
sudo systemctl start kube-apiserver.service
sudo systemctl start kubelet.service
sudo systemctl start kube-proxy.service
sudo systemctl start kube-controller-manager.service
sudo systemctl start kube-scheduler.service
sudo systemctl enable etcd.service
sudo systemctl enable kube-apiserver.service
sudo systemctl enable kubelet.service
sudo systemctl enable kube-proxy.service
sudo systemctl enable kube-controller-manager.service
sudo systemctl enable kube-scheduler.service

cat >apache.json <<EOT
{
  "id": "apache",
  "desiredState": {
    "manifest": {
      "version": "v1beta1",
      "id": "apache-1",
      "containers": [{
        "name": "master",
        "image": "fedora/apache",
        "ports": [{
          "containerPort": 80,
          "hostPort": 80
        }]
      }]
    }
  },
  "labels": {
    "name": "apache"
  }
}
EOT

sudo kubecfg -c apache.json create pods
sudo kubecfg -c apache.json list pods

curl localhost

References

@demosdemon
Copy link

May I suggest a helpful comment saying that the raw image is required to be named disk.raw in the tarball.

@eklitzke
Copy link

Can you provide an example using kubectl instead of kubecfg?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment