{"id":3475,"date":"2015-08-12T23:35:01","date_gmt":"2015-08-13T05:35:01","guid":{"rendered":"http:\/\/benincosa.com\/?p=3475"},"modified":"2015-08-13T13:23:41","modified_gmt":"2015-08-13T19:23:41","slug":"kubernetes-on-metacloud-copc","status":"publish","type":"post","link":"https:\/\/benincosa.com\/?p=3475","title":{"rendered":"Kubernetes on Metacloud (COPC)"},"content":{"rendered":"<p>The <a href=\"http:\/\/www.oscon.com\/open-source-2015\/public\/schedule\/detail\/45281\">Kubernetes 1.0 launch happened July 21st at OSCON<\/a> here in Portland, OR and I was super happy to be there in the back of the room picking up loads of free stickers while the big event happened. \u00a0I spent the day before at a <a href=\"http:\/\/www.oscon.com\/open-source-2015\/public\/schedule\/detail\/45373\">Kubernetes bootcamp<\/a>, which was really just a lab on using it on GCE (or GKE for containers) and it was pretty cool. \u00a0But now I felt I really should do a little more to understand it.<\/p>\n<p>To install Kubernetes on Metacloud (or what Cisco now calls<a href=\"http:\/\/www.cisco.com\/c\/en\/us\/products\/cloud-systems-management\/openstack-private-cloud\/index.html\"> Cisco OpenStack Private Cloud<\/a>) I&#8217;m using CoreOS. \u00a0I like CoreOS because its lightweight and built for containers. \u00a0There are a few guides out there like the one on Digital Ocean that is pretty outdated (not even a year old!) that was good. \u00a0For installing Kubernetes on CoreOS on OpenStack its pretty easy now!<\/p>\n<p>I should note, that I&#8217;m using Cisco OpenStack Private Cloud, but these steps can be used with any OpenStack distribution. \u00a0I followed most of the documentation based on the <a href=\"https:\/\/github.com\/GoogleCloudPlatform\/kubernetes\/blob\/release-1.0\/docs\/getting-started-guides\/coreos\/coreos_multinode_cluster.md\">Kubernetes documentation<\/a>. \u00a0(You&#8217;ll notice on there site that there is no instructions for OpenStack. \u00a0I opened an<a href=\"https:\/\/github.com\/GoogleCloudPlatform\/kubernetes\/issues\/12587\"> issue<\/a> of which I hope to help with).<\/p>\n<p>Anyway, the gist is here with all <a href=\"https:\/\/gist.github.com\/vallard\/9583d9e20a3a338dc139\">the instructions<\/a>, but I&#8217;m more of the mindset to use Ansible.<\/p>\n<h3>Install Kubernetes<\/h3>\n<p>First download the cloud-init files that Kelsey Hightower created. \u00a0These make installing this super simple. \u00a0Get the <a href=\"https:\/\/github.com\/kubernetes\/kubernetes\/blob\/release-1.0\/docs\/getting-started-guides\/coreos\/cloud-configs\/master.yaml\">master<\/a> and the <a href=\"https:\/\/github.com\/GoogleCloudPlatform\/kubernetes\/blob\/release-1.0\/docs\/getting-started-guides\/coreos\/cloud-configs\/node.yaml\">node<\/a>.<\/p>\n<p>We then create a master task that looks something like this:<\/p>\n<pre class=\"theme:solarized-dark lang:sh decode:true\">  tasks: \r\n  - name: Deploy Kubernetes Master to Kube01\r\n    nova_compute:\r\n      state: present\r\n      auth_url: \"{{ lookup('env', 'OS_AUTH_URL') }}\"\r\n      login_username: \"{{ lookup('env', 'OS_USERNAME') }}\"\r\n      login_password: \"{{ lookup('env', 'OS_PASSWORD') }}\"\r\n      login_tenant_name: \"{{ project_name }}\"\r\n      name: \"{{ item }}\"\r\n      image_name: \"{{ coreos_image_name }}\"\r\n      key_name: \"{{ keypair }}\"\r\n      # 3 is m1.large\r\n      flavor_id: 3\r\n      meta: \r\n        group: Kube-Servers\r\n      security_groups: \"{{ security_group }}\"\r\n      user_data:  \"{{ lookup('file', 'files\/master.yaml') }}\"\r\n      floating_ip_pools:\r\n        - \"nova\"\r\n    with_items:\r\n      - kube01\r\n    register: nova<\/pre>\n<p>Here I&#8217;m heavily using environment variables that should be defined elsewhere. \u00a0I call them out with a vars_file that has most of these. \u00a0The credentials are stored in the ~\/.bash_profile and so live externally to the vars_file. \u00a0That&#8217;s where we keep our username, endpoints, and password.<\/p>\n<p>You&#8217;ll have to have a CoreOS image already created in your cloud to use this. \u00a0I got mine from <a href=\"https:\/\/coreos.com\/os\/docs\/latest\/booting-on-openstack.html\">here<\/a>. \u00a0Then I used glance and uploaded it.<\/p>\n<p>The user_data points to use the file that was created by the Kubernetes community and will configure upon boot the parameters required for Kubernetes.<\/p>\n<p>The minion nodes configuration is similar:<\/p>\n<pre class=\"theme:solarized-dark lang:yaml decode:true\">- name: Deploy Kubernetes Minions\r\n    nova_compute:\r\n      state: present\r\n      auth_url: \"{{ lookup('env', 'OS_AUTH_URL') }}\"\r\n      login_username: \"{{ lookup('env', 'OS_USERNAME') }}\"\r\n      login_password: \"{{ lookup('env', 'OS_PASSWORD') }}\"\r\n      login_tenant_name: \"{{ project_name }}\"\r\n      name: \"{{ item }}\"\r\n      image_name: \"{{ coreos_image_name }}\"\r\n      key_name: \"{{ keypair }}\"\r\n      # 3 is m1.large\r\n      flavor_id: 3\r\n      meta: \r\n        group: Kube-Servers\r\n      security_groups: \"{{ security_group }}\"\r\n      user_data:  \"{{ lookup('file', 'files\/node.yaml') }}\"\r\n      floating_ip_pools:\r\n        - \"nova\"\r\n    with_items:\r\n      - kube02\r\n      - kube03\r\n      - kube04<\/pre>\n<p>Note that you have to edit the node.yml file to point to the master (kube01 in our example).<\/p>\n<p>At this point I&#8217;ve been a little lazy and didn&#8217;t go do the variable substitution. \u00a0Someday, I&#8217;ll get around to that. \u00a0But as a hint, since we registered &#8216;nova&#8217; in the first task we can get the private IP address with this flag:<\/p>\n<pre class=\"theme:solarized-dark lang:yaml decode:true \">- debug: var=nova.results[0].private_ip<\/pre>\n<p>Just put that after the creation of the master.<\/p>\n<p>The github repo for this is <a href=\"https:\/\/github.com\/vallard\/Ansible-Kubernetes\">here<\/a>.<\/p>\n<h3>Using Kubectl<\/h3>\n<p>Once our cluster is installed we can now run stuff. \u00a0I have a mac so I set it up like this following the instructions <a href=\"https:\/\/github.com\/kubernetes\/kubernetes\/blob\/release-1.0\/docs\/getting-started-guides\/aws\/kubectl.md\">here<\/a>:<\/p>\n<pre class=\"theme:solarized-dark lang:sh decode:true\">cd \/usr\/local\/bin\/\r\nwget https:\/\/storage.googleapis.com\/kubernetes-release\/release\/v1.0.1\/bin\/darwin\/amd64\/kubectl --no-check-certificate\r\nchmod +x kubectl<\/pre>\n<p>Now we set the proxy up so we can run kubectl on our master:<\/p>\n<pre class=\"theme:solarized-dark lang:sh decode:true\">ssh -f -nNT -L 8080:127.0.0.1:8080 kube01<\/pre>\n<p>Make sure that when you check your path, kubectl from \/usr\/local\/bin shows up instead of maybe one from Google&#8217;s GCE stuff.<\/p>\n<p>Check that it works by running:<\/p>\n<pre class=\"theme:solarized-dark lang:sh decode:true\">kubectl version\r\nkubectl get nodes\r\nkubectl get pods\r\n\r\n<\/pre>\n<p>Now we can launch something! \u00a0Let&#8217;s use the Hello World example on the Kubernetes documentation site. \u00a0Create this file and name it hello-world.yaml<\/p>\n<pre class=\"theme:solarized-dark lang:yaml decode:true\">apiVersion: v1\r\nkind: Pod\r\nmetadata:\r\n  name: hello-world\r\nspec:  # specification of the pod\u2019s contents\r\n  restartPolicy: Never\r\n  containers:\r\n  - name: hello\r\n    image: \"ubuntu:14.04\"\r\n    command: [\"\/bin\/echo\",\"hello\u201d,\u201dworld\"]<\/pre>\n<p>Then create it:<\/p>\n<pre class=\"theme:solarized-dark lang:sh decode:true \">kubectl create -f .\/hello-world.yaml<\/pre>\n<p>There are several other examples as well and I encourage you to go to the <a href=\"http:\/\/kubernetes.io\/v1.0\/docs\/user-guide\/deploying-applications.html\">official guides<\/a>! \u00a0Let me know if this was helpful to you with a quick <a href=\"http:\/\/twitter.com\/vallard\">hello on Twitter<\/a>!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Kubernetes 1.0 launch happened July 21st at OSCON here in Portland, OR and I was super happy to be there in the back of the room picking up loads of free stickers while the big event happened. \u00a0I spent the day before at a Kubernetes bootcamp, which was really just a lab on using&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1013,638,797,1001],"tags":[734,731,1011,798],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts\/3475"}],"collection":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3475"}],"version-history":[{"count":4,"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts\/3475\/revisions"}],"predecessor-version":[{"id":3493,"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts\/3475\/revisions\/3493"}],"wp:attachment":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}