From 7ac3b126918d8e0d3730cad6af363453e67892e6 Mon Sep 17 00:00:00 2001 From: Princess Oluebube Egbuna <13929923+Princesso@users.noreply.github.com> Date: Thu, 13 Apr 2023 16:27:04 +0100 Subject: [PATCH] Add devrel section to the docs (#1124) * Add devrel section to the docs * Fix exclamation mark not allowed * Fix PR comments * Add approved articles to docs * Fix spellings * Rename Kubernetes School with Kubernetes Knowlege hub * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Rita Watson <117382432+ritawatson@users.noreply.github.com> * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Rita Watson <117382432+ritawatson@users.noreply.github.com> * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Rita Watson <117382432+ritawatson@users.noreply.github.com> * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Rita Watson <117382432+ritawatson@users.noreply.github.com> * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Rita Watson <117382432+ritawatson@users.noreply.github.com> * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Rita Watson <117382432+ritawatson@users.noreply.github.com> * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Rita Watson <117382432+ritawatson@users.noreply.github.com> * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Rita Watson <117382432+ritawatson@users.noreply.github.com> * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Rita Watson <117382432+ritawatson@users.noreply.github.com> * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Rita Watson <117382432+ritawatson@users.noreply.github.com> * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Rita Watson <117382432+ritawatson@users.noreply.github.com> * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md Co-authored-by: Karl Cardenas * Update with PR comments * Apply suggestions from code review * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/01-tutorials.md Co-authored-by: Karl Cardenas * Update content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md Co-authored-by: Karl Cardenas * Remove tutorial and community sections --------- Co-authored-by: Princess Co-authored-by: Rita Watson <117382432+ritawatson@users.noreply.github.com> Co-authored-by: Karl Cardenas --- content/docs/19-kubernetes-knowlege-hub.md | 27 +++ .../19-kubernetes-knowlege-hub/00-how-to.md | 28 +++ ...o-retrieve-images-from-private-registry.md | 185 +++++++++++++++ .../06-deploy-stateless-frontend-app.md | 215 ++++++++++++++++++ .../01-tutorials.md | 21 ++ src/shared/mdx/components/index.js | 2 +- 6 files changed, 477 insertions(+), 1 deletion(-) create mode 100644 content/docs/19-kubernetes-knowlege-hub.md create mode 100644 content/docs/19-kubernetes-knowlege-hub/00-how-to.md create mode 100644 content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md create mode 100644 content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md create mode 100644 content/docs/19-kubernetes-knowlege-hub/01-tutorials.md diff --git a/content/docs/19-kubernetes-knowlege-hub.md b/content/docs/19-kubernetes-knowlege-hub.md new file mode 100644 index 0000000000..4c42a08a57 --- /dev/null +++ b/content/docs/19-kubernetes-knowlege-hub.md @@ -0,0 +1,27 @@ +--- +title: "Kubernetes Knowledge Hub" +metaTitle: "Kubernetes Knowledge Hub" +metaDescription: "Kubernetes Knowledge Hub Respository" +icon: "bookmark" +hideToCSidebar: true +hideToC: true +fullWidth: true +--- + +import Tabs from 'shared/components/ui/Tabs'; +import WarningBox from 'shared/components/WarningBox'; +import InfoBox from 'shared/components/InfoBox'; +import PointsOfInterest from 'shared/components/common/PointOfInterest'; +import Tooltip from "shared/components/ui/Tooltip"; + +# Welcome to the Spectro Cloud Knowledge Portal + +Welcome to the Spectro Cloud Kubernetes Knowledge Hub. You will find core Kubernetes tutorials, how-tos, frequently asked questions, and community curated resources. + +If you have a topic in mind you would like to see, use the Feedback app on the lower-right-hand corner. +
+ +- [How-To](/kubernetes-knowlege-hub/how-to) + + +
diff --git a/content/docs/19-kubernetes-knowlege-hub/00-how-to.md b/content/docs/19-kubernetes-knowlege-hub/00-how-to.md new file mode 100644 index 0000000000..7ec1a8ab1d --- /dev/null +++ b/content/docs/19-kubernetes-knowlege-hub/00-how-to.md @@ -0,0 +1,28 @@ +--- +title: "How to" +metaTitle: "Get started with a quick Kubernetes How-to" +metaDescription: "Kubernetes School with How to" +icon: "book" +hideToC: false +fullWidth: false +hiddenFromNav: false +--- + +import Tabs from 'shared/components/ui/Tabs'; +import WarningBox from 'shared/components/WarningBox'; +import InfoBox from 'shared/components/InfoBox'; +import PointsOfInterest from 'shared/components/common/PointOfInterest'; +import Tooltip from "shared/components/ui/Tooltip"; + +# How To + +Learn about core Kubernetes concepts and how you can apply them on Spectro Cloud Palette. + +# Core Kubernetes +- [How To Retrieve Images from a Private Registry in Kubernetes](/kubernetes-knowlege-hub/how-to/how-to-retrieve-images-from-private-registry) + + + +- [Deploy a Stateless Frontend Application on Kubernetes](/kubernetes-knowlege-hub/how-to/deploy-stateless-frontend-app) + +
diff --git a/content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md b/content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md new file mode 100644 index 0000000000..1cd325c57b --- /dev/null +++ b/content/docs/19-kubernetes-knowlege-hub/00-how-to/02-how-to-retrieve-images-from-private-registry.md @@ -0,0 +1,185 @@ +--- +title: "Retrieve Images from a Private Registry" +metaTitle: "Retrieve Images from a Private Registry" +metaDescription: "Create a Kubernetes Secret to retrieve images from a private registry." +icon: "" +hideToC: false +fullWidth: false +hiddenFromNav: false +--- + +import Tabs from 'shared/components/ui/Tabs'; +import WarningBox from 'shared/components/WarningBox'; +import InfoBox from 'shared/components/InfoBox'; +import PointsOfInterest from 'shared/components/common/PointOfInterest'; +import Tooltip from "shared/components/ui/Tooltip"; + +# How To Retrieve Images from a Private Registry in Kubernetes + +Kubernetes is an open-source container orchestration platform that enables efficient management, deployment, and scaling of containerized applications. + +By default, Docker and Kubernetes allow a limited number of unauthenticated pulls from a Docker registry, such as Docker Hub. When you exceed this limit, you will not be able to pull any more images until the limit resets. + +The limit is based on the IP address of the machine that is making the pulls, so it applies to all containers running on that machine. + +To avoid this issue, we recommend that you authenticate with the Docker registry before pulling images, especially if you are pulling from a private registry. This ensures you have access to the images you need and can pull them without restrictions or limitations. + +To log into a Docker registry from Kubernetes, you must create a secret that contains your registry credentials. You can use this secret in a Kubernetes deployment configuration to pull images from the registry. + +In this tutorial, you will log into a private docker registry to pull existing images of an application that you will deploy in Kubernetes. + +# Prerequisites + +- The kubectl [command-line tool](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/). Kubectl allows you to connect to, configure and work with your clusters through the command line. +- Access to a private registry. [DockerHub](https://hub.docker.com/) offers a single private registry on the free tier. If you do not have a personal registry account, you can use DockerHub. +- Access to a running Kubernetes cluster. To learn how to create clusters in different environments using Palette, review guides listed under [Clusters](docs.spectrocloud.com/clusters) or visit the [Palette Onboarding Workflow](docs.spectrocloud.com/getting-started/onboarding-workflow#paletteonboardingworkflow) guide. To learn how to create a Kubernetes cluster from scratch, check out the [Create a Cluster](https://kubernetes.io/docs/tutorials/kubernetes-basics/create-cluster/) Kubernetes resource. + +The following example explains how you can create a secret and use it in a Kubernetes deployment: + +## Create a Credentials JSON File + +First, create a file called **registry-creds.json** that contains your registry credentials in the following format: + +```json +{ + "auths": { + "example.registry.com": { + "username": "username", + "password": "password" + } + } +} +``` + +Keeping passwords in plain text is unsafe. Kubernetes automatically encodes passwords used to create a secret in base64. Encoding passwords does not mean your passwords cannot be decoded. + +## Create a Kubernetes Secret + +Use the kubectl command-line tool to generate a secret from the **registry-creds.json** file: + +```bash +kubectl create secret generic myregistrykey --from-file=registry-creds.json +``` + +You can use the command below to view the secret created in detail. + +```bash +kubectl get secret/myregistrykey --output json +``` + +The command output displays the content of the **registry-creds.json** file as base 64 encoded. + +```json +{ + "apiVersion": "v1", + "data": { + "registry-creds.json": "ewogICJhdXRocyI6IHsKICAgICJleGFtcGxlLnJlZ2lzdHJ5LmNvbSI6IHsKICAgICAgInVzZXJuYW1lIjogInRlc3RfdXNlcm5hbWUiLAogICAgICAicGFzc3dvcmQiOiAidGVzdF9wYXNzd29yZCIKICAgIH0KICB9Cn0K" + }, + "kind": "Secret", + "metadata": { + "creationTimestamp": "2023-03-22T08:44:26Z", + "name": "myregistrykey", + "namespace": "default", + "resourceVersion": "1552285", + "uid": "ccfb047b-67c8-446b-a69a-6eb762c3100f" + }, + "type": "Opaque" +} +``` + +Invoke the following command to decode the secret you created to verify that secrets are not secure. + +```bash +kubectl get secret myregistrykey --output jsonpath='{.data.registry-creds\.json}' | base64 --decode +``` + +The output of issuing the command above is the content of the JSON file you used to create the secret. + +```json +{ + "auths": { + "example.registry.com": { + "username": "username", + "password": "password" + } + } +} +``` + +## Add Secret to Deployment Config + +In your Kubernetes deployment configuration, specify the name of the secret you just created for the imagePullSecrets parameter: + +```yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-deployment +spec: + replicas: 3 + selector: + matchLabels: + app: my-app + template: + metadata: + labels: + app: my-app + spec: + containers: + - name: my-container + image: registry.example.com/my-image + imagePullSecrets: + - name: myregistrykey +``` + +## Apply the Deployment Configuration + +```bash +kubectl apply --file deployment.yaml +``` + +With this configuration in place, Kubernetes will use the registry credentials in the `myregistrykey` secret to log into the registry and pull the specified image when deploying the application. + +## Other Docker Registry Authentication Methods + +An alternative way to log into a Docker registry from Kubernetes is by using the command line. + +Authenticate to the private registry. Here’s an example of how to do this: + +```bash +$ kubectl create secret docker-registry \ + --docker-server= \ + --docker-username= \ + --docker-password= \ + --docker-email= +``` + +In the snippet above, **``** refers to a unique name for the secret, **``** is the URL of the private registry. Replace the **``** with the username for authentication and **``** with the password for authentication. Also, replace **``** + with the email associated with the authentication credentials. + +Add the secret created in the previous step to the default service account with the following code. + +```bash +kubectl patch serviceaccount default \ + --port '{"imagePullSecrets": [{"name": ""}]}' +``` + +Replace **``** with the secret created in the previous step. + +Once you are authenticated and have added the secret to your default service account, you can use the kubectl command to pull images from the registry and deploy them to your Kubernetes cluster as follows. + +```bash +kubectl run \ + --image=/: \ + --port= +``` + +The line above will create a new deployment using the image specified from the private registry. + +# Next Steps + +Accessing images from a private registry in Kubernetes can be challenging due to the need to authenticate with the registry. + +To solve this challenge, you have learned how to create a Kubernetes secret with your Docker registry credentials and use it in a Kubernetes deployment configuration. This allows you to pull images from your private registry without restrictions or limitations. + +To learn more about Kubernetes and how to use it to deploy your application, check out [Palette's Dev Engine](/devx/apps/deploy-app) and how it can reduce the challenges often encountered with deploying apps to Kubernetes. You can also read about [how to deploy a stateless frontend application](/kubernetes-knowlege-hub/how-to/deploy-stateless-frontend-app) on Kubernetes or join our [slack channel](https://join.slack.com/t/spectrocloudcommunity/shared_invite/zt-1mw0cgosi-hZJDF_1QU77vF~qNJoPNUQ). Learn from other Kubernetes users and get to know fellow community members. diff --git a/content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md b/content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md new file mode 100644 index 0000000000..c85dc29854 --- /dev/null +++ b/content/docs/19-kubernetes-knowlege-hub/00-how-to/06-deploy-stateless-frontend-app.md @@ -0,0 +1,215 @@ +--- +title: 'Deploy a Stateless Frontend Application With Kubernetes' +metaTitle: 'Deploy a Stateless Frontend Application With Kubernetes' +metaDescription: 'One of the key benefits of using Kubernetes is that it provides a consistent and reliable way to deploy applications across different environments, including on-premises data centers and cloud infrastructure. Learn how to deploy a stateless frontend application in Kubernetes.' +icon: "" +hideToC: false +fullWidth: false +hideToCSidebar: false +hiddenFromNav: false +--- + +import Tabs from 'shared/components/ui/Tabs'; +import WarningBox from 'shared/components/WarningBox'; +import InfoBox from 'shared/components/InfoBox'; + +# How To Deploy a Stateless Frontend App with Kubernetes + +## Introduction + +Kubernetes is a container orchestration platform that is widely used for deploying and managing containerized applications. + +One of the key benefits of using Kubernetes is that it provides a consistent and reliable way to deploy applications across different environments, including on-prem data centers and cloud infrastructure. + +Deploying a stateless frontend application with Kubernetes can be a straightforward process, although it requires an understanding of the key concepts and best practices of Kubernetes. + +In this tutorial, you will containerize a date suggester app built in React and deploy it with Kubernetes. This application is bootstrapped with [Create React App](https://create-react-app.dev/). + +# Requirements + +- An installation of [Node.js and NPM](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) on your machine. Node is a Javascript runtime environment and will enable React to run on your machine. + + +- A clone of the application from the [date suggestions app](https://github.com/Princesso/date-buddy.git) on GitHub. Cloning the application will enable you to follow this tutorial step by step. + + +- A Docker account and a [Docker installation](https://docs.docker.com/engine/install/ubuntu/) on your machine. + + +- A running Kubernetes cluster. You can create one on [Spectro Cloud’s Palette](https://docs.spectrocloud.com/getting-started/#deployingyourfirstcluster) or [use other methods to create a cluster](https://www.notion.so/How-To-Create-a-Kubernetes-Cluster-bf707518b6bf4a918d8b11a570eabed6). + + +- An installation of the [kubectl command-line tool](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/) on your machine and connected to your cluster. +- A LoadBalancer. You can [create a LoadBanlacer](https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/) with a public cloud provider, or use the [minikube tunnel](https://minikube.sigs.k8s.io/docs/commands/tunnel/) to trick a local cluster into exposing a resource. + +## About the Application + +The date suggester app is written in React. It takes a single date input on when a user will like to go on a date and displays a date idea for the selected date. + +The app data comes from a JSON file that lives on the frontend app. + +## Clone the Application. + +Use the command shown below to clone the application from GitHub. + +```bash +git clone https://github.com/spectrocloud/date-buddy +``` + +If you prefer to use a different stateless frontend app, you can do so. You may, however, get different results than in this tutorial. This tutorial only serves as a guide. + +## Create a Dockerfile on the App’s Root Directory. + +Before continuing this step, ensure Docker is installed on your machine. In the app's root directory, create a file named **Dockerfile**. + +```bash +touch Dockerfile +``` + +In a text editor, add the lines below to the Dockerfile. + +```bash +FROM node:12 + +WORKDIR /date-suggestions + +COPY package*.json ./ + +RUN npm install + +COPY . . + +EXPOSE 3000 + +CMD ["npm", "start"] +``` + +Also, create a **.dockerignore** file and add the following lines to it. + +```bash +/node_modules +/.pnp +.pnp.js +/coverage +``` + +## Build a Docker Image of the Application. + +This step packages the application into a portable image. To build the app’s image, run the Docker `build` command as shown: + +```bash +docker build --tag date-suggestions . +``` + +## Create a Kubernetes Deployment. + +Before continuing with this step, ensure that you have access to a Kubernetes cluster, as explained in the [prerequisites](https://www.notion.so/How-To-Deploy-A-Stateless-Frontend-App-with-Kubernetes-b885ae2307e94ef191a1b713fe29c81f). + +In the application's root directory, create a Kubernetes Deployment file using the `kubectl` command below: + +```bash +kubectl create deploy date-suggestions --image=date-suggestions --replicas=2 --port=3000 --dry-run=client --output yaml +``` + +The command output is a YAML representation of the deployment, similar to the lines below. + +```yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: date-suggestions +spec: + selector: + matchLabels: + app: date-suggestions + replicas: 2 + template: + metadata: + labels: + app: date-suggestions + spec: + containers: + - name: date-suggestions + image: date-suggestions + ports: + - containerPort: 3000 +``` + + +You can use the output YAML to create a deployment file. Use the redirect operator `>` to turn the command output into a **deployment.yaml** file. + +```bash +kubectl create deploy date-suggestions --image=date-suggestions --replicas=2 --port=3000 --dry-run=client --output yaml > deployment.yaml +``` + +Alternatively, you can use the `touch` command to create the **deployment.yaml** file, and then copy the YAML output from the command to create a deployment to it. + +```bash +touch deployment.yaml +``` + +## Create a Kubernetes Service. + +Create and populate a Kubernetes Service file in the app's root directory. By default, your application will only be accessible within the cluster. You'll need to create a Kubernetes service resource to expose the application to resources outside the Kubernetes cluster. A service resource creates an abstraction over a set of pods that provides discovery and routing between them. + +To create a service, use the `kubectl expose` command as shown below: + +```bash +kubectl expose deployment date-suggestions --type=LoadBalancer --port=80 --target-port=3000 --name=date-suggestion-service --dry-run=client --output yaml +``` + +The output of running the command will be similar to the YAML below: + +```yaml +apiVersion: v1 +kind: Service +metadata: + name: date-suggestions-service +spec: + type: LoadBalancer + selector: + app: date-suggestions + ports: + - protocol: TCP + port: 80 + targetPort: 3000 +``` + +If everything looks good, modify the command to redirect the output YAML to the file **service.yaml**. + +```bash +kubectl expose deployment date-suggestions --type=LoadBalancer --port=80 --target-port=3000 --name=date-suggestion-service --dry-run=client --output yaml > service.yaml +``` + +You can also create a YAML file with the `touch` command and add the output of the `kubectl expose` command to it. + +```bash +touch service.yaml +``` + +Copy and paste the following line of code to the service file. + +## Deploy the Application. +Use the kubectl command line connected to the cluster you created earlier, and deploy the application by applying the file's content to Kubernetes. + +```bash +kubectl apply --file deployment.yaml --file service.yaml +``` + +## Confirm that deployment was successful. + +Once the deployment and service files have been applied, you should be able to access your app by issuing the following command: + +```bash +kubectl get service date-suggestions-service --output=jsonpath='{.status.loadBalancer.ingress[0].ip}' +``` + +This will display the URL of your app that you can use to can access it in a web browser. + +# Next Steps + +Deploying a stateless frontend application with Kubernetes can be a straightforward process if you understand the fundamental concepts of Kubernetes. + +In this tutorial, you containerized a stateless React-based app and deployed it with Kubernetes by creating a Dockerfile, building a Docker image, creating a Kubernetes deployment, and creating a Kubernetes service. + +To learn more about Kubernetes, you can join our [slack channel](https://join.slack.com/t/spectrocloudcommunity/shared_invite/zt-1mw0cgosi-hZJDF_1QU77vF~qNJoPNUQ). Learn from other Kubernetes users and get to know fellow community members. \ No newline at end of file diff --git a/content/docs/19-kubernetes-knowlege-hub/01-tutorials.md b/content/docs/19-kubernetes-knowlege-hub/01-tutorials.md new file mode 100644 index 0000000000..502e079c77 --- /dev/null +++ b/content/docs/19-kubernetes-knowlege-hub/01-tutorials.md @@ -0,0 +1,21 @@ +--- +title: "Tutorials" +metaTitle: "Get started with a quick Kubernetes How-to" +metaDescription: "Kubernetes School with How to" +icon: "book" +hideToC: false +fullWidth: false +hiddenFromNav: true +--- + +import Tabs from 'shared/components/ui/Tabs'; +import WarningBox from 'shared/components/WarningBox'; +import InfoBox from 'shared/components/InfoBox'; +import PointsOfInterest from 'shared/components/common/PointOfInterest'; +import Tooltip from "shared/components/ui/Tooltip"; + +# Tutorials + +Learn about core Kubernetes concepts and how you can apply them on Spectro Cloud Palette. + +
\ No newline at end of file diff --git a/src/shared/mdx/components/index.js b/src/shared/mdx/components/index.js index 860313513c..963737755c 100644 --- a/src/shared/mdx/components/index.js +++ b/src/shared/mdx/components/index.js @@ -101,7 +101,7 @@ function generateHeadingId(children) { }, ""); } - return title.replace(/\s+/g, "").toLowerCase(); + return title?.replace?.(/\s+/g, "")?.toLowerCase?.(); } function Pre(props) {