# Ungraded Lab: Practice Kubernetes in your Local Environment
In the previous reading item, you went through the basics of Kubernetes by doing imperative commands in the interactive shell (i.e. with `kubectl`). It shows how this tool can be used to orchestrate containers to host an application. If you haven't done that exercise, we highly encourage you to go back because we will assume that you are already familiar with the concepts discussed in [those 6 modules](https://kubernetes.io/docs/tutorials/kubernetes-basics/). This lab will be an extension of that activity and will show a few more concepts to prepare you for this week's graded assignment. Specifically, you will:
* setup Kubernetes in your local machine for learning and development
* create Kubernetes objects using YAML files
* deploy containers running a Tensorflow model server
* access the deployment using a Nodeport service
* autoscale the deployment to dynamicaly handle incoming traffic
You should be able to run all the commands using Mac and Linux (tested on Ubuntu) CLI, Windows Powershell (run as Administrator) and Git Bash. In case you have limited resources or can't install in your workstation, don't worry about it. You can still refer to this document later and we'll show the expected output at each step.
## Installation
First, you will setup your machine to run a local Kubernetes cluster. This gives you more freedom to tweak settings and implement more features compared to the online Katacoda environment you used in the Kubernetes tutorial. It's a great tool for learning and for local development as well. There are several Kubernetes distributions and the one best suited for our purpose is [Minikube](https://minikube.sigs.k8s.io/docs/). You might remember it being mentioned in the first module of the Kubernetes basics exercise.
*Note: If you installed Docker for Desktop in the previous ungraded labs, you may have noticed that it also has a Kubernetes Engine that can be enabled in the Settings. At the moment, we found some limitations for it in some OS and it needs more tweaking or workarounds to make all the exercises here work. Thus, we recommend using Minikube for a more seamless experience.*
You will need to install the following tools to go through this lab:
* **curl** - a command-line tool for transferring data using various network protocols. You may have a already installed this in the Docker ungraded lab but in case you haven't, [here is one reference](https://reqbin.com/Article/InstallCurl) to do so. You will use this to query your model later.
* **Virtualbox** - Minikube is meant to run in a virtual machine (VM) so you will need virtualization software to act as the VM driver. While you can also specify `docker` as the VM driver, we found that it has limitations so it's best to use Virtualbox instead. Installation instructions can be found [here](https://www.virtualbox.org/wiki/Downloads). When prompted by your OS, make sure to allow network traffic for this software so you won't have firewall issues later on.
* **kubectl** - the command line tool for interacting with Kubernetes clusters. Installation instructions can be found [here](https://kubernetes.io/docs/tasks/tools/)
* **Minikube** - a Kubernetes distribution geared towards new users and development work. It is not meant for production deployments however since it can only run a single node cluster on your machine. Installation instructions [here](https://minikube.sigs.k8s.io/docs/start/).
<details>
<summary> <i>Windows Users: Please click here for additional notes. </i></summary>
1. Make sure that the directories to the `curl` and `kubectl` binaries are setup in your system `PATH` (or `Path`). That will allow you to execute these in the command line from any directory. Instructions can be found [here](https://www.computerhope.com/issues/ch000549.htm) in case you need to review how this is done.
2. You may need to append a `.exe` in the commands later to make use of `curl` and `kubectl`. For example, if you see `curl --help`, please do `curl.exe --help` instead.
3. In case you have [Git for Windows](https://git-scm.com/download/win) setup in your machine, then you can use the `Git Bash` CLI bundled with that package instead of `Windows Powershell`. Just search for it in the Search Bar to see if it is already in your system. That CLI runs like a Linux terminal so most of the commands in the next sections will run as is. But we still placed instructions in case you can only use Powershell.
4. If you encounter errors about running VirtualBox alongside WSL2 similar to [this](https://github.com/MicrosoftDocs/WSL/issues/798), you can fallback to using Docker as the VM runtime for Minikube. Instructions are shown in the next sections in case you follow this path.
---
</details>
</br>
## Architecture
The application you'll be building will look like the figure below:
<img src='img/kubernetes.png' alt='img/kubernetes.png'>
You will create a deployment that spins up containers that runs a model server. In this case, that will be from the `tensorflow/serving` image you already used in the previous labs. The deployment can be accessed by external terminals (i.e. your users) through an exposed service. This brings inference requests to the model servers and responds with predictions from your model.
Lastly, the deployment will spin up or spin down pods based on CPU utilization. It will start with one pod but when the load exceeds a pre-defined point, it will spin up additional pods to share the load.
## Start Minikube
You are now almost ready to start your Kubernetes cluster. There is just one more additional step. As mentioned earlier, Minikube runs inside a virtual machine. That implies that the pods you will create later on will only see the volumes inside this VM. Thus, if you want to load a model into your pods, then you should first mount the location of this model inside Minikube's VM. Let's set that up now.
You will be using the `half_plus_two` model that you saw in earlier ungraded labs. You can copy it to your `/var/tmp` directory (Mac, Linux) or `C:/tmp` (Windows) so we'll have a common directory to mount to the VM. You can use the command below for Mac and Linux:
```
cp -R ./saved_model_half_plus_two_cpu /var/tmp
```
If you're using Windows (not WSL), then you can use the GUI to create a `tmp` folder under your `C:` drive then copy the folder there. You should have a `C:/tmp/saved_model_half_plus_two_cpu` folder as a result
Now you're ready to start Minikube! Run the command below to initialize the VM with Virtualbox and mount the folder containing your model file:
For Mac and Linux:
```
minikube start --mount=True --mount-string="/var/tmp:/var/tmp" --vm-driver=virtualbox
```
For Windows:
```
minikube start --mount=True --mount-string="C:/tmp:/var/tmp" --vm-driver=virtualbox
```
<details>
<summary> <i>Troubleshooting: Please click here if you're getting errors with these commands. </i></summary>
* Some learners reported prompts about driver errors and thus, they can't make Virtualbox the VM driver when launching Minikube. In case you run into the same issue and can't resolve it, you can just fallback to Docker:
```
minikube start --mount=True --mount-string="C:/tmp:/var/tmp" --vm-driver=docker
```
This would require revisions to some of the commands later and we placed that in *Troubleshooting* sections as well.
* Some learners reported getting an error about trouble accessing `https://k8s.gcr.io` and needing to configure a proxy. For that, please do these steps before starting `minikube`:
* Run `minikube ip`. This will display an IP address in your terminal.
* Replace `<your_minikube_ip>` in the command below with the IP address you saw above:
```
set NO_PROXY=localhost,127.0.0.1,10.96.0.0/12,192.168.59.0/24,192.168.49.0/24,192.168.39.0/24,<your_minikube_ip>
```
* Start minikube
---
</details>
</br>
## Creating Objects with YAM
没有合适的资源?快使用搜索试试~ 我知道了~
入门机器学习:手把手教你实现简单的算法
共130个文件
png:38个
ipynb:21个
md:13个
需积分: 5 1 下载量 19 浏览量
2024-01-03
10:02:55
上传
评论
收藏 28.55MB ZIP 举报
温馨提示
图像分类 - 使用机器学习算法对图片进行分类,可以应用于自动识别车辆模型、品类识别、安防等领域。 推荐系统 - 比如在电商平台上,根据用户的历史购买行为和喜好,使用机器学习算法生成个性化推荐,提高用户粘性、促进销售。 自然语言处理 - 使用机器学习算法实现文本分类、情感分析、信息抽取、问答系统等任务,帮助机器自动理解和生成自然语言。 海量数据处理 - 通过使用机器学习算法处理和分析海量数据,可以发现潜在的商业机会和风险、提高精准营销效果和客户满意度等。 智能医疗 - 使用机器学习算法来辅助医生进行疾病诊断、预测,提高诊断的准确性和速度。 自动驾驶 - 通过结合计算机视觉、深度学习和强化学习等技术,让车辆自动感知周围环境、规划路径、调整速度进行自主驾驶。 量化投资 - 使用机器学习算法分析和预测证券市场,帮助投资者制定和优化投资策略,提高投资收益。
资源推荐
资源详情
资源评论
收起资源包目录
入门机器学习:手把手教你实现简单的算法 (130个子文件)
models.config 467B
jena_climate_2009_2016.csv 41.16MB
variables.data-00000-of-00001 20B
Dockerfile 227B
Dockerfile 227B
.gitignore 2KB
.gitignore 8B
WISDM_ar_latest.tar.gz 10.88MB
molecules.tar.gz 10KB
variables.index 172B
server.ipynb 324KB
C3_W4_Lab_2_TFX_Evaluator.ipynb 53KB
C1W2_Ungraded_Lab_Birds_Cats_Dogs.ipynb 50KB
C3_W4_Lab_1_TFMA.ipynb 49KB
C4_W3_Lab_2_TFX_Custom_Components.ipynb 45KB
C4_W2_Lab_4_Apache_Beam_and_Tensorflow.ipynb 41KB
C2_W4_Lab_1_WeatherData.ipynb 40KB
C3_W1_Lab_2_TFX_Tuner_and_Trainer.ipynb 37KB
C4_W3_Lab_1_Kubeflow_Pipelines.ipynb 33KB
C3_W4_Lab_3_Fairness_Indicators.ipynb 31KB
C3_W2_Lab_2_Algorithmic_Dimensionality.ipynb 28KB
C3_W2_Lab_3_Quantization_and_Pruning.ipynb 27KB
C2_W4_Lab_2_Signals.ipynb 25KB
C3_W5_Lab_2_Permutation_Importance.ipynb 24KB
C4_W1_Lab_3_TFS.ipynb 23KB
C3_W2_Lab_1_Manual_Dimensionality.ipynb 22KB
C3_W3_Lab_2_Knowledge_Distillation.ipynb 22KB
C3_W3_Lab_1_Distributed_Training.ipynb 20KB
C3_W1_Lab_1_Keras_Tuner.ipynb 20KB
C3_W5_Lab_1_Shap_Values.ipynb 15KB
client.ipynb 11KB
apples.jpg 67KB
clock3.jpg 60KB
clock2.jpg 55KB
clock.jpg 53KB
fruits.jpg 44KB
apple.jpg 41KB
car.jpg 41KB
oranges.jpg 37KB
simple_dag.jpg 16KB
highlevel.jpg 13KB
car2.jpg 9KB
car3.jpg 9KB
car1.jpg 6KB
dog_example.json 1.34MB
batch_2.json 6KB
batch_1.json 5KB
batch_0.json 5KB
2.json 340B
0.json 335B
1.json 302B
LICENSE 11KB
README.md 23KB
README.md 15KB
C4_W1_Optional_Lab_1.md 15KB
README.md 14KB
README.md 13KB
README.md 10KB
README.md 9KB
C4_W1_Lab_2_TFS_Docker.md 8KB
README.md 7KB
C4_W1_Lab_1_Docker_Intro.md 6KB
README.md 3KB
mac_m1.md 1KB
README.md 412B
saved_model.pb 12KB
wine-95-fixed.pkl 30KB
wine-95.pkl 29KB
wine.pkl 20KB
wine.pkl 20KB
wine.pkl 20KB
test_data.pkl 5KB
logs.png 297KB
autoscaled.png 282KB
autoscale_start.png 267KB
complete.png 264KB
progress.png 242KB
kfp_ui.png 239KB
etl.png 196KB
upload.png 181KB
locust-home.png 174KB
upload_pipeline.png 170KB
complete_pipeline.png 167KB
overview.png 164KB
initial_load.png 163KB
models_api.png 149KB
xgboost.png 116KB
predict.png 102KB
cleanup.png 102KB
url.png 93KB
token.png 93KB
notebook.png 83KB
gcs.png 80KB
kubernetes.png 62KB
terminal_launcher.png 62KB
dag_kfp.png 61KB
your-fork.png 59KB
workflow-run.png 49KB
deploy.png 49KB
close.png 48KB
共 130 条
- 1
- 2
资源评论
汀、人工智能
- 粉丝: 7w+
- 资源: 369
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功