> For the complete documentation index, see [llms.txt](https://anida-huang.gitbook.io/cloud-communication/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://anida-huang.gitbook.io/cloud-communication/qi-mo/20201215-kubernetes-san.md).

# 20201215 kubernetes (三)

## 課堂資訊

{% embed url="<https://www.cnblogs.com/along21/p/10333086.html>" %}

{% embed url="<https://www.coder.work/article/7319208>" %}

| Proxy Server | Proxy |
| ------------ | ----- |
| 正向代理伺服器      | 客戶端   |
| 反向代理伺服器      | 服務器   |

### Ingress

![工作示意圖](/files/-MOt5Fnuy0ld67LIboGY)

## 課堂練習

### Ingress

{% tabs %}
{% tab title="vm1" %}

> #### 創建部署

```
cd test-ingress-nginx
```

```
kubectl apply -f mandatory.yaml
```

```
kubectl apply -f service-nodeport.yaml
```

```
ls
```

```
gedit service-nodeport.yaml mandatory.yaml &
```

![](/files/-MOt8AbskTZ9ChmKyD9S)

```
kubectl get deployment
```

```
kubectl get deployment -n ingress-nginx
```

```
kubectl get svc -n ingress-nginx
```

```
kubectl get pods -n ingress-nginx
```

![](/files/-MOt8TKLVLU7gmzhXNQO)

> #### 創建 Ingress，代理到後端 nginx 服務

```
kubectl get deployment
```

```
kubectl delete deployment myweb
```

```
kubectl delete svc myweb
```

```
kubectl get svc
```

```
kubectl apply -f httpd.yaml
```

```
gedit httpd.yaml
```

```
kubectl get deployment
```

```
kubectl get svc
```

```
gedit ingress-httpd.yaml
```

{% hint style="info" %}
modify`serviceName` to`httpd`
{% endhint %}

![](/files/-MOtEezKnINEa-YniNLQ)

```
curl [httpd_CLUSTER-IP]
```

```
kubectl apply -f ingress-httpd.yaml
```

```
kubectl get ingress
```

```
kubectl get svc
```

```
kubectl get pod -n ingress-nginx
```

```
kubectl get pod -n ingress-nginx -o wide
```

![](/files/-MOtHOvS-k-zXWcaJsBW)

{% hint style="info" %}
modify`C:\Windows\System32\drivers\etc` 中的`hosts`

```
192.168.8.130          www.a.com
192.168.8.131          www.a.com
```

{% endhint %}

![](/files/-MOtIYQ_2ecK69Ne5GXK)

```
kubectl get pod
```

![](/files/-MOtNEYWmk2tyOgdQd3r)

```
kubectl get pod -o wide
```

```
kubectl exec [vm3_httpdName] -it -- bash
```

```
cd htdocs/
```

```
echo "vm3 www.a.com" > hi.htm
```

```
ls
```

```
exit
```

![](/files/-MOtNSdui-bbX4_wNlNO)

```
kubectl exec [vm2_httpdName] -it -- bash
```

```
cd htdocs/
```

```
echo "vm2 www.a.com" > hi.htm
```

```
ls
```

```
exit
```

![](/files/-MOtOBZCbPiVh9o_bR8l)

```
cp httpd.yaml httpd2.yaml
```

```
cp ingress-httpd.yaml ingress-httpd2.yaml
```

```
gedit httpd2.yaml ingress-httpd2.yaml
```

![](/files/-MOtVR-qhNgras_UBODJ)

![](/files/-MOtV-MNGZ-Yk62abHQV)

```
kubectl apply -f httpd2.yaml
```

```
kubectl apply -f ingress-httpd2.yaml
```

```
kubectl get ingress
```

```
kubectl get pod
```

```
kubectl exec [http2_Name] -it -- bash
```

```
cd htdocs/
```

```
echo "www.b.com" > hi.htm
```

![](/files/-MOtW1wHC6KTpMJkjn19)

> #### Deployment

```
kubectl get deployment
```

```
kubectl describe deployment httpd
```

![](/files/-MOtXKNVNpO9gXTZIp24)

```
kubectl get replicaset
```

```
kubectl get deployment httpd2
```

```
kubectl edit deployment httpd2
```

```
cd
```

```
ls
```

![](/files/-MOta1VIQCoRCltc7VPz)

```
kubectl apply -f cronjob.yml
```

```
kubectl get pod
```

```
cat cronjob.yml
```

```
kubectl get pod -o wide
```

![](/files/-MOtcaRrCRzHIj3swQCb)
{% endtab %}
{% endtabs %}
