{"id":6263,"date":"2019-07-26T18:06:06","date_gmt":"2019-07-26T18:06:06","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=6263"},"modified":"2021-11-16T11:14:44","modified_gmt":"2021-11-16T11:14:44","slug":"create-google-kubernetes-enginegke-cluster-using-command-line","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/create-google-kubernetes-enginegke-cluster-using-command-line\/","title":{"rendered":"Create Google Kubernetes Engine(GKE) Cluster using command line"},"content":{"rendered":"<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">#Instructions from this URL: https:\/\/cloud.google.com\/sdk\/docs\/quickstart-debian-ubuntu<\/span>\n<span class=\"hljs-comment\"># Create environment variable for correct distribution<\/span>\nCLOUD_SDK_REPO=<span class=\"hljs-string\">\"cloud-sdk-$(lsb_release -c -s)\"<\/span>\n\n<span class=\"hljs-comment\"># Add the Cloud SDK distribution URI as a package source<\/span>\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"deb http:\/\/packages.cloud.google.com\/apt $CLOUD_SDK_REPO main\"<\/span> | sudo tee -a \/etc\/apt\/sources.<span class=\"hljs-keyword\">list<\/span>.d\/google-cloud-sdk.<span class=\"hljs-keyword\">list<\/span>\n\n<span class=\"hljs-comment\"># Import the Google Cloud Platform public key<\/span>\ncurl https:<span class=\"hljs-comment\">\/\/packages.cloud.google.com\/apt\/doc\/apt-key.gpg | sudo apt-key add -<\/span>\n\n<span class=\"hljs-comment\"># Update the package list and install the Cloud SDK<\/span>\nsudo apt-get update \nsudo apt-get install google-cloud-sdk\n\n<span class=\"hljs-comment\">#Authenticate our console session with gcloud<\/span>\ngcloud init --console-only\n\n<span class=\"hljs-comment\">#Create a named gcloud project<\/span>\ngcloud projects create psdemogke --name=<span class=\"hljs-string\">\"Kubernetes-Cloud\"<\/span>\n\n<span class=\"hljs-comment\">#Set our current project context<\/span>\ngcloud config set project psdemogke\n\n<span class=\"hljs-comment\">#Enable GKE services in our current project<\/span>\ngcloud services enable container.googleapis.com\n\n<span class=\"hljs-comment\">#You may have to adjust your resource limits and enabled billing here based on your subscription here.<\/span>\n<span class=\"hljs-comment\">#Go to https:\/\/console.cloud.google.com<\/span>\n<span class=\"hljs-comment\">#From the Navigation menu on the top left, browse to Compute-&gt;Kubernetes Engine.<\/span>\n<span class=\"hljs-comment\">#Click enable billing. Click Set Account.<\/span>\n\n<span class=\"hljs-comment\">#Tell GKE to create a single zone, three node cluster for us. 3 is the default size.<\/span>\n<span class=\"hljs-comment\">#https:\/\/cloud.google.com\/compute\/quotas#checking_your_quota<\/span>\ngcloud container clusters create cscluster --region us-central1-a\n\n<span class=\"hljs-comment\">#Get our credentials for kubectl<\/span>\ngcloud container clusters get-credentials cscluster --zone us-central1-a --project psdemogke\n\n<span class=\"hljs-comment\">#Check out out lists of kubectl contexts<\/span>\nkubectl config get-contexts\n\n<span class=\"hljs-comment\">#set our current context to the GKE context<\/span>\nkubectl config <span class=\"hljs-keyword\">use<\/span>-<span class=\"hljs-title\">context<\/span> <span class=\"hljs-title\">gke_psdemogke_us<\/span>-<span class=\"hljs-title\">central1<\/span>-<span class=\"hljs-title\">a_cscluster<\/span>\n\n#<span class=\"hljs-title\">run<\/span> <span class=\"hljs-title\">a<\/span> <span class=\"hljs-title\">command<\/span> <span class=\"hljs-title\">to<\/span> <span class=\"hljs-title\">communicate<\/span> <span class=\"hljs-title\">with<\/span> <span class=\"hljs-title\">our<\/span> <span class=\"hljs-title\">cluster<\/span>.\n<span class=\"hljs-title\">kubectl<\/span> <span class=\"hljs-title\">get<\/span> <span class=\"hljs-title\">nodes<\/span>\n\n#<span class=\"hljs-title\">Delete<\/span> <span class=\"hljs-title\">our<\/span> <span class=\"hljs-title\">GKE<\/span> <span class=\"hljs-title\">cluster<\/span>\n#<span class=\"hljs-title\">gcloud<\/span> <span class=\"hljs-title\">container<\/span> <span class=\"hljs-title\">clusters<\/span> <span class=\"hljs-title\">delete<\/span> <span class=\"hljs-title\">cscluster<\/span> --<span class=\"hljs-title\">zone<\/span>=<span class=\"hljs-title\">us<\/span>-<span class=\"hljs-title\">central1<\/span>-<span class=\"hljs-title\">a<\/span> \n\n#<span class=\"hljs-title\">Delete<\/span> <span class=\"hljs-title\">our<\/span> <span class=\"hljs-title\">project<\/span>.\n#<span class=\"hljs-title\">gcloud<\/span> <span class=\"hljs-title\">projects<\/span> <span class=\"hljs-title\">delete<\/span> <span class=\"hljs-title\">psdemogke<\/span>\n\n\n#<span class=\"hljs-title\">Get<\/span> <span class=\"hljs-title\">a<\/span> <span class=\"hljs-title\">list<\/span> <span class=\"hljs-title\">of<\/span> <span class=\"hljs-title\">all<\/span> <span class=\"hljs-title\">contexts<\/span> <span class=\"hljs-title\">on<\/span> <span class=\"hljs-title\">this<\/span> <span class=\"hljs-title\">system<\/span>.\n<span class=\"hljs-title\">kubectl<\/span> <span class=\"hljs-title\">config<\/span> <span class=\"hljs-title\">get<\/span>-<span class=\"hljs-title\">contexts<\/span>\n\n#<span class=\"hljs-title\">Let<\/span>'<span class=\"hljs-title\">s<\/span> <span class=\"hljs-title\">set<\/span> <span class=\"hljs-title\">to<\/span> <span class=\"hljs-title\">the<\/span> <span class=\"hljs-title\">kubectl<\/span> <span class=\"hljs-title\">context<\/span> <span class=\"hljs-title\">back<\/span> <span class=\"hljs-title\">to<\/span> <span class=\"hljs-title\">our<\/span> <span class=\"hljs-title\">local<\/span> <span class=\"hljs-title\">custer<\/span>\n<span class=\"hljs-title\">kubectl<\/span> <span class=\"hljs-title\">config<\/span> <span class=\"hljs-title\">use<\/span>-<span class=\"hljs-title\">context<\/span> <span class=\"hljs-title\">kubernetes<\/span>-<span class=\"hljs-title\">admin<\/span>@<span class=\"hljs-title\">kubernetes<\/span>\n\n#<span class=\"hljs-title\">use<\/span> <span class=\"hljs-title\">kubectl<\/span> <span class=\"hljs-title\">get<\/span> <span class=\"hljs-title\">nodes<\/span>\n<span class=\"hljs-title\">kubectl<\/span> <span class=\"hljs-title\">get<\/span> <span class=\"hljs-title\">nodes<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_95945\"><iframe loading=\"lazy\"  id=\"_ytid_42356\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_95945\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[4859],"tags":[],"class_list":["post-6263","post","type-post","status-publish","format-standard","hentry","category-kubernetes"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/6263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=6263"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/6263\/revisions"}],"predecessor-version":[{"id":25487,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/6263\/revisions\/25487"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=6263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=6263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=6263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}