{"id":1984,"date":"2023-03-30T18:09:13","date_gmt":"2023-03-30T15:09:13","guid":{"rendered":"https:\/\/upcloud.com\/global\/us\/resources\/tutorials\/get-started-managed-kubernetes\/"},"modified":"2023-03-30T18:09:13","modified_gmt":"2023-03-30T15:09:13","slug":"get-started-managed-kubernetes","status":"publish","type":"tutorial","link":"https:\/\/upcloud.com\/global\/resources\/tutorials\/get-started-managed-kubernetes\/","title":{"rendered":"How to get started with Managed Kubernetes\u00ae"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Kubernetes\u00ae is an open-source container orchestration system that automates containerised applications&#8217; deployment, scaling and management. Managed Kubernetes offers a fully managed solution which allows you to create and begin using Kubernetes clusters in just a few minutes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Through Kubernetes, you can manage and orchestrate containers (such as Docker) across multiple hosts. Using Kubernetes makes it quick and easy to deploy and manage applications on the cloud. It provides features like self-healing, automatic scaling, and service discovery.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating new Managed Kubernetes cluster<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The simplest way to create a cluster is by using your Control Panel. You can do so by following the steps outlined below.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To start, log in to the&nbsp;<a href=\"https:\/\/hub.upcloud.com\/\">UpCloud Control Panel<\/a> or <a href=\"https:\/\/signup.upcloud.com\/\" data-type=\"URL\" data-id=\"https:\/\/signup.upcloud.com\/\">sign up<\/a> if you haven&#8217;t done so.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next, go to the Kubernetes page using the menu on the left-hand side.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then click the <em>Create new cluster<\/em> button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/managed-kubernetes-dashboard-1024x535.png\" alt=\"-\" class=\"wp-image-39780\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now, configure your Kubernetes cluster according to your preferences by selecting the availability zone, a private network and node groups.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/chrome_qfiiuItMlI-649x1024.png\" alt=\"-\" class=\"wp-image-48458\" style=\"object-fit:cover\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Next, select a Private Network for your worker nodes. This network should be in the same zone as your created cluster. The network cannot be connected to an existing cluster, cannot have an attached router, and should have DHCP enabled with the default route from DHCP disabled. For the IP network of your SDN network, you can use for example&nbsp;<tt>10.0.1.0\/24<\/tt>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Just below the network options, you can also choose the Kubernetes version your cluster is deployed with. In most cases, you should be deploying with the most up-to-date one unless your application has a specific reason to select a particular older Kubernetes update.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/managed-kubernetes-configuration-3-1024x988.png\" alt=\"-\" class=\"wp-image-39779\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In the next section, you have the option to enable API access to the cluster from any specific IP address or range. It&#8217;s also possible to remove all IP restrictions from the API access, e.g. for troubleshooting.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then create a node group or use the default node group.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/managed-kubernetes-configuration-2.png\" alt=\"-\" class=\"wp-image-39778\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A node group is a group of workers with identical image templates. You can have multiple node groups with differing configurations and usages.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/4-new-managed-kubernetes-cluster-nodes-config.png\" alt=\"-\" class=\"wp-image-33052\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">You also have the option to include key-value labels. The labels are forwarded to kubernetes node definitions and can be used to organize and select subsets of Kubernetes objects.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/5-new-managed-kubernetes-cluster-nodes-labels.png\" alt=\"-\" class=\"wp-image-33053\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Optionally, expand the <em>Advanced options<\/em> to find the <em>Anti-affinity option<\/em> and the ability to include <em>SSH keys<\/em>. Note that you will need to add your SSH public key first in your <a href=\"https:\/\/hub.upcloud.com\/account\/ssh\">account details<\/a> before deploying it to your Kubernetes cluster.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/6-new-managed-kubernetes-cluster-nodes-ssh.png\" alt=\"-\" class=\"wp-image-33054\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Lastly, name your cluster and when all set, click the&nbsp;<em>Create<\/em>&nbsp;button.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Cluster creation will take a couple of minutes as worker nodes are provisioned and a DNS record is prepared. While your cluster is being created, continue on to setting up your control plane access.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Connecting to the cluster<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To be able to deploy workloads to your Managed Kubernetes cluster, you&#8217;ll need to configure a connection to it using the kubectl command-line tool with a kubeconfig file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can download your cluster&#8217;s kubeconfig file from your cluster&#8217;s Overview page and set it up on your local computer. Kubeconfig files are used to organize information about clusters, users, namespaces, and authentication mechanisms.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/8-new-managed-kubernetes-cluster-1-874x1024.png\" alt=\"-\" class=\"wp-image-33064\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The kubeconfig file allows you to access your cluster easily via the command line. If you do not yet have kubectl installed, <a href=\"https:\/\/kubernetes.io\/docs\/tasks\/tools\/#kubectl\" target=\"_blank\" rel=\"noopener\">follow the instructions for your computer system<\/a> then continue with the step below.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add the <tt>kubeconfig.yaml<\/tt> file to your system with the command provided in the Kubeconfig section of your cluster Overview. Make sure to set the path correctly depending on where you saved the configuration file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">export KUBECONFIG=\/{path}\/{cluster-name}_kubeconfig.yaml<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You will likely want to add the same command to your profile as well to have it automatically set when you open a new terminal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When set, test that your cluster is accessible and can be reached by using <tt>kubectl<\/tt>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">kubectl config view<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">apiVersion: v1\nclusters:\n- cluster:\n    certificate-authority-data: DATA+OMITTED\n    server: https:\/\/lb-0a8fdaf728bd487e8c4ecf5396a8cb25-1.upcloudlb.com:6443\n  name: my-kube-cluster\ncontexts:\n- context:\n    cluster: my-kube-cluster\n    user: my-kube-cluster-admin\n  name: my-kube-cluster-admin@my-kube-cluster\ncurrent-context: my-kube-cluster-admin@my-kube-cluster\nkind: Config\npreferences: {}\nusers:\n- name: my-kube-cluster-admin\n  user:\n    client-certificate-data: DATA+OMITTED\n    client-key-data: DATA+OMITTED<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you are seeing an output similar to the example above, you are ready to start deploying applications to your new Managed Kubernetes cluster.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Testing app deployment to the cluster<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now that you have created your Managed Kubernetes cluster and connected to it using kubectl, you probably want to test it out. This can be done quickly and easily with just a few commands with kubectl.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Start by deploying a&nbsp;<em>Hello UKS<\/em>&nbsp;application to your newly created cluster with the command below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">kubectl create deployment --image=ghcr.io\/upcloudltd\/hello hello-uks<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">deployment.apps\/hello-uks created<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Next, expose the application at port 80 making it accessible via HTTP.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">kubectl expose deployment hello-uks --port=80 --target-port=80 --type=LoadBalancer<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">service\/hello-uks exposed<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This bit will take a moment. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can keep an eye on the services with the next command to see when the app becomes available.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">kubectl get services -w<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">NAME        TYPE          CLUSTER-IP     EXTERNAL-IP       PORT(S)       AGE\nhello-uks   LoadBalancer  10.133.236.77  &lt;pending&gt;         80:31655\/TCP  5s\nkubernetes  ClusterIP     10.128.0.1     &lt;none&gt;            443\/TCP       5m28s\nhello-uks   LoadBalancer  10.133.236.77  &lt;pending&gt;         80:31655\/TCP  2m20s\nhello-uks   LoadBalancer  10.133.236.77  lb-0ad...lb.com   80:31655\/TCP  2m20s<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once the <tt>hello-uks<\/tt> app has been successfully exposed, you&#8217;ll see a load balancer domain name under the external IPs column. It can then be called on the command line.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">curl lb-0ad5c7ed5fac4bdc8b7178264467c320-1.upcloudlb.com<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">Hello! \ud83d\udc4b\n\nHostname: hello-uks-77547779f-bkrm8\nAddress:  192.168.3.238:80\n\nUpCloudLtd \/ hello-container at 72507bf9<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can also open the load balancer address on your web browser.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/10-hello-uks-1024x418.png\" alt=\"Hello UKS app screen\" class=\"wp-image-33058\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s it! You should now have a fully functional Managed Kubernetes with kubectl configured to connect to the control plane.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can learn more about <a href=\"https:\/\/github.com\/UpCloudLtd\/uks-beta\/blob\/main\/ccm\/README.md\" target=\"_blank\" rel=\"noopener\">exposing services<\/a> or adding <a href=\"https:\/\/github.com\/UpCloudLtd\/uks-beta\/blob\/main\/storage\/README.md\" target=\"_blank\" rel=\"noopener\">persistent volumes<\/a> for storage on our GitHub page.<\/p>\n","protected":false},"author":3,"featured_media":33067,"comment_status":"open","ping_status":"closed","template":"","community-category":[229,268,247],"class_list":["post-1984","tutorial","type-tutorial","status-publish","has-post-thumbnail","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/1984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial"}],"about":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/types\/tutorial"}],"author":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/comments?post=1984"}],"version-history":[{"count":0,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/1984\/revisions"}],"wp:attachment":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/media?parent=1984"}],"wp:term":[{"taxonomy":"community-category","embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/community-category?post=1984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}