Skip to content

Commit

Permalink
Adapt Kubernetes basics tutorials for local use
Browse files Browse the repository at this point in the history
Avoid relying on Katacoda.

Co-authored-by: Divya Mohan <divya.mohan0209@gmail.com>
  • Loading branch information
sftim and divya-mohan0209 committed Mar 28, 2023
1 parent 3e51968 commit 252bcf6
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 67 deletions.
23 changes: 0 additions & 23 deletions content/en/docs/contribute/style/style-guide.md
Expand Up @@ -385,29 +385,6 @@ The output is:
Beware.
{{< /warning >}}

### Katacoda Embedded Live Environment

This button lets users run Minikube in their browser using the Katacoda Terminal.
It lowers the barrier of entry by allowing users to use Minikube with one click instead of going through the complete
Minikube and Kubectl installation process locally.

The Embedded Live Environment is configured to run `minikube start` and lets users complete tutorials in the same window
as the documentation.

{{< caution >}}
The session is limited to 15 minutes.
{{< /caution >}}

For example:

```
{{</* kat-button */>}}
```

The output is:

{{< kat-button >}}

## Common Shortcode Issues

### Ordered Lists
Expand Down
9 changes: 5 additions & 4 deletions content/en/docs/tutorials/hello-minikube.md
Expand Up @@ -98,9 +98,10 @@ Pod and restarts the Pod's Container if it terminates. Deployments are the
recommended way to manage the creation and scaling of Pods.

1. Use the `kubectl create` command to create a Deployment that manages a Pod. The
Pod runs a Container based on the provided Docker image.
Pod runs a Container based on the provided Docker image.

```shell
# Run a test container image that includes a webserver
kubectl create deployment hello-node --image=registry.k8s.io/e2e-test-images/agnhost:2.39 -- /agnhost netexec --http-port=8080
```

Expand Down Expand Up @@ -162,7 +163,7 @@ Kubernetes [*Service*](/docs/concepts/services-networking/service/).
The `--type=LoadBalancer` flag indicates that you want to expose your Service
outside of the cluster.

The application code inside the image `registry.k8s.io/echoserver` only listens on TCP port 8080. If you used
The application code inside the test image only listens on TCP port 8080. If you used
`kubectl expose` to expose a different port, clients could not connect to that other port.

2. View the Service you created:
Expand Down Expand Up @@ -236,7 +237,7 @@ The minikube tool includes a set of built-in {{< glossary_tooltip text="addons"
The 'metrics-server' addon is enabled
```

3. View the Pod and Service you created:
3. View the Pod and Service you created by installing that addon:

```shell
kubectl get pod,svc -n kube-system
Expand Down Expand Up @@ -286,7 +287,7 @@ kubectl delete service hello-node
kubectl delete deployment hello-node
```

Stop the minikube cluster:
Stop the Minikube cluster

```shell
minikube stop
Expand Down
@@ -1,6 +1,10 @@
---
title: Using Minikube to Create a Cluster
weight: 10
description: |-
Learn what a Kubernetes cluster is.
Learn what Minikube is.
Start a Kubernetes cluster.
---

<!DOCTYPE html>
Expand All @@ -20,7 +24,7 @@ <h3>Objectives</h3>
<ul>
<li>Learn what a Kubernetes cluster is.</li>
<li>Learn what Minikube is.</li>
<li>Start a Kubernetes cluster using an online terminal.</li>
<li>Start a Kubernetes cluster on your computer.</li>
</ul>
</div>

Expand Down Expand Up @@ -84,18 +88,16 @@ <h2 style="color: #3771e3;">Cluster Diagram</h2>
<div class="col-md-8">
<p>When you deploy applications on Kubernetes, you tell the control plane to start the application containers. The control plane schedules the containers to run on the cluster's nodes. <b>The nodes communicate with the control plane using the <a href="/docs/concepts/overview/kubernetes-api/">Kubernetes API</a></b>, which the control plane exposes. End users can also use the Kubernetes API directly to interact with the cluster.</p>

<p>A Kubernetes cluster can be deployed on either physical or virtual machines. To get started with Kubernetes development, you can use Minikube. Minikube is a lightweight Kubernetes implementation that creates a VM on your local machine and deploys a simple cluster containing only one node. Minikube is available for Linux, macOS, and Windows systems. The Minikube CLI provides basic bootstrapping operations for working with your cluster, including start, stop, status, and delete. For this tutorial, however, you'll use a provided online terminal with Minikube pre-installed.</p>
<p>A Kubernetes cluster can be deployed on either physical or virtual machines. To get started with Kubernetes development, you can use Minikube. Minikube is a lightweight Kubernetes implementation that creates a VM on your local machine and deploys a simple cluster containing only one node. Minikube is available for Linux, macOS, and Windows systems. The Minikube CLI provides basic bootstrapping operations for working with your cluster, including start, stop, status, and delete.</p>

<p>Now that you know more about what Kubernetes is, visit <a href="/docs/tutorials/hello-minikube/">Hello Minikube</a>
to try this out on your computer.</p>

<p>Now that you know what Kubernetes is, let's go to the online tutorial and start our first cluster!</p>

</div>
</div>
<br>

<div class="row">
<div class="col-md-12">
<a class="btn btn-lg btn-success" href="/docs/tutorials/kubernetes-basics/create-cluster/cluster-interactive/" role="button">Start Interactive Tutorial <span class="btn__next"></span></a>
</div>
<p>Once you've done that, move on to <a href="/docs/tutorials/kubernetes-basics/deploy-app/deploy-intro/">Using <tt>kubectl</tt> to create a Deployment</a>.</p>
</div>

</main>
Expand Down
@@ -1,6 +1,9 @@
---
title: Using kubectl to Create a Deployment
weight: 10
description: |-
Learn about application Deployments.
Deploy your first app on Kubernetes with kubectl.
---

<!DOCTYPE html>
Expand All @@ -14,26 +17,25 @@
<main class="content">

<div class="row">

<div class="col-md-8">
<h3>Objectives</h3>
<ul>
<li>Learn about application Deployments.</li>
<li>Deploy your first app on Kubernetes with kubectl.</li>
</ul>
</div>
<ul>
<li>Learn about application Deployments.</li>
<li>Deploy your first app on Kubernetes with kubectl.</li>
</ul>
</div>

<div class="col-md-8">
<h3>Kubernetes Deployments</h3>
<p>
Once you have a running Kubernetes cluster, you can deploy your containerized applications on top of it.
To do so, you create a Kubernetes <b>Deployment</b> configuration. The Deployment instructs Kubernetes
Once you have a <a href="/docs/tutorials/kubernetes-basics/create-cluster/cluster-intro/">running Kubernetes cluster</a>, you can deploy your containerized applications on top of it.
To do so, you create a Kubernetes <b>Deployment</b>. The Deployment instructs Kubernetes
how to create and update instances of your application. Once you've created a Deployment, the Kubernetes
control plane schedules the application instances included in that Deployment to run on individual Nodes in the
cluster.
</p>

<p>Once the application instances are created, a Kubernetes Deployment Controller continuously monitors those instances. If the Node hosting an instance goes down or is deleted, the Deployment controller replaces the instance with an instance on another Node in the cluster. <b>This provides a self-healing mechanism to address machine failure or maintenance.</b></p>
<p>Once the application instances are created, a Kubernetes Deployment controller continuously monitors those instances. If the Node hosting an instance goes down or is deleted, the Deployment controller replaces the instance with an instance on another Node in the cluster. <b>This provides a self-healing mechanism to address machine failure or maintenance.</b></p>

<p>In a pre-orchestration world, installation scripts would often be used to start applications, but they did not allow recovery from machine failure. By both creating your application instances and keeping them running across Nodes, Kubernetes Deployments provide a fundamentally different approach to application management. </p>

Expand Down Expand Up @@ -72,7 +74,7 @@ <h2 style="color: #3771e3;">Deploying your first app on Kubernetes</h2>
<div class="row">
<div class="col-md-8">

<p>You can create and manage a Deployment by using the Kubernetes command line interface, <b>Kubectl</b>. Kubectl uses the Kubernetes API to interact with the cluster. In this module, you'll learn the most common Kubectl commands needed to create Deployments that run your applications on a Kubernetes cluster.</p>
<p>You can create and manage a Deployment by using the Kubernetes command line interface, <b>kubectl</b>. Kubectl uses the Kubernetes API to interact with the cluster. In this module, you'll learn the most common Kubectl commands needed to create Deployments that run your applications on a Kubernetes cluster.</p>

<p>When you create a Deployment, you'll need to specify the container image for your application and the number of replicas that you want to run. You can change that information later by updating your Deployment; Modules <a href="/docs/tutorials/kubernetes-basics/scale/scale-intro/">5</a> and <a href="/docs/tutorials/kubernetes-basics/update/update-intro/">6</a> of the bootcamp discuss how you can scale and update your Deployments.</p>

Expand All @@ -91,18 +93,69 @@ <h2 style="color: #3771e3;">Deploying your first app on Kubernetes</h2>
<div class="col-md-8">
<p>
For your first Deployment, you'll use a hello-node application packaged in a Docker container that uses NGINX to echo back all the requests. (If you didn't already try creating a hello-node application and deploying it using a container, you can do that first by following the instructions from the <a href="/docs/tutorials/hello-minikube/">Hello Minikube tutorial</a>).
<p>

<p>Now that you know what Deployments are, let's go to the online tutorial and deploy our first app!</p>
<p>You will need to have installed kubectl as well. If you need to install it, visit <a href="/docs/tasks/tools/#kubectl">install tools</a>.</p>
<p>Now that you know what Deployments are, let's deploy our first app!</p>
</div>
</div>
<br>

<div class="row">
<div class="col-md-8">
<h3>kubectl basics</h3>
<p>The common format of a kubectl command is: <code>kubectl <i>action resource</i></code></p>
<p>This performs the specified <em>action</em> (like create, describe or delete) on the specified <em>resource</em> (like <tt>node</tt> or <tt>deployment</tt>). You can use <code>-<span />-help</code> after the subcommand to get additional info about possible parameters (for example: <code>kubectl get nodes --help</code>).</p>
<p>Check that kubectl is configured to talk to your cluster, by running the <b><code>kubectl version</code></b> command.</p>
<p>Check that kubectl is installed and you can see both the client and the server versions.</p>
<p>To view the nodes in the cluster, run the <b><code>kubectl get nodes</code></b> command.</p>
<p>You see the available nodes. Later, Kubernetes will choose where to deploy our application based on Node available resources.</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<a class="btn btn-lg btn-success" href="/docs/tutorials/kubernetes-basics/deploy-app/deploy-interactive/" role="button">Start Interactive Tutorial <span class="btn__next"></span></a>
<h3>Deploy an app</h3>
<p>Let’s deploy our first app on Kubernetes with the <code>kubectl create deployment</code> command. We need to provide the deployment name and app image location (include the full repository url for images hosted outside Docker hub).</p>
<p><b><code>kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1</code></b></p>
<p>Great! You just deployed your first application by creating a deployment. This performed a few things for you:</p>
<ul>
<li>searched for a suitable node where an instance of the application could be run (we have only 1 available node)</li>
<li>scheduled the application to run on that Node</li>
<li>configured the cluster to reschedule the instance on a new Node when needed</li>
</ul>
<p>To list your deployments use the <code>kubectl get deployments</code> command:</p>
<p><b><code>kubectl get deployments</code></b></p>
<p>We see that there is 1 deployment running a single instance of your app. The instance is running inside a container on your node.</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h3>View the app</h3>
<p>Pods that are running inside Kubernetes are running on a private, isolated network.
By default they are visible from other pods and services within the same kubernetes cluster, but not outside that network.
When we use <code>kubectl</code>, we're interacting through an API endpoint to communicate with our application.</p>
<p>We will cover other options on how to expose your application outside the kubernetes cluster in Module 4.</p>
<p>The <code>kubectl</code> command can create a proxy that will forward communications into the cluster-wide, private network. The proxy can be terminated by pressing control-C and won't show any output while its running. </p>
<p><strong>You need to open a second terminal window to run the proxy.</strong></p>
<p><b><code>kubectl proxy</b></code>
<p>We now have a connection between our host (the online terminal) and the Kubernetes cluster. The proxy enables direct access to the API from these terminals.</p>
<p>You can see all those APIs hosted through the proxy endpoint. For example, we can query the version directly through the API using the <code>curl</code> command:</p>
<p><b><code>curl http://localhost:8001/version</code></b></p>
<div class="alert alert-info note callout" role="alert"><strong>Note:</strong> If Port 8001 is not accessible, ensure that the <code>kubectl proxy</code> that you started above is running in the second terminal.</div>
<p>The API server will automatically create an endpoint for each pod, based on the pod name, that is also accessible through the proxy.</p>
<p>First we need to get the Pod name, and we'll store in the environment variable <tt>POD_NAME</tt>:</p>
<p><b><code>export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')</code></b><br />
<b><code>echo Name of the Pod: $POD_NAME</code></b></p>
<p>You can access the Pod through the proxied API, by running:</p>
<p><b><code>curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME/</code></b></p>
<p>In order for the new Deployment to be accessible without using the proxy, a Service is required which will be explained in the next modules.</p>
</div>

</div>
<div class="row">
<p>
Once you're ready, move on to <a href="/docs/tutorials/kubernetes-basics/explore/explore-intro/" title="Viewing Pods and Nodes">Viewing Pods and Nodes</a>.</p>
</p>
</div>


</main>

Expand Down

0 comments on commit 252bcf6

Please sign in to comment.