### Kubernetes basic concepts
* [What can Kubernetes do for you](https://kubernetes.io/docs/tutorials/kubernetes-basics/)
* [Kubernetes design](https://kubernetes.io/docs/concepts/architecture/cloud-controller/#design)
* [Kubernetes cheat sheet](https://kubernetes.io/docs/reference/kubectl/cheatsheet/)
---
### Install kubeadm, kubectl & kubelet
* [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
* [kubeadm](https://kubernetes.io/docs/setup/independent/install-kubeadm/)
* demo
---
### Trouble shooting
- Linux OS (My script only support ubuntu 16+)
- Hardware ( Enable VT-x, 2+ Core , 2G RAM )
- Swap must be off
- disable swap immediately
```bash
sudo swapoff -a
```
- comment out the swap drive from fstab
```
# swap was on ...
# UUID=XXXXXXX-XXXXX-XXXX
```
### Check out the docker and kubelet status
```bash
systemctl status docker
systemctl status kubelet
```
---
#### Create a single cluster
```
# Reset kubeadm
kubeadm reset
# Cleanup old network setting
# Init kubedadm
kubeadm init
# Install pod network
kubeadm apply -f <pod_network>
# Remove master node schedule restriction
kubeadm draint ...
```
---
#### Install kubernetes dashboard
* Add a new account and role binding
* Install kubernetes dashboard
* Install kubernetes charts
---
#### Add another node to the cluster
* Install kubeadm, kubectl, kubelet
* Reset kubeadm (optional)
* Add a new node to cluster
---
#### Deploy a stateful application
* Folllowing the instruction to deploy a stateful application
---
#### Scale up the applications
```bash
kubectl top pod/node
kubectl -n <NAME_SPACE> scale --replicas=<number> \
deployment <SERVICE_NAME>
```
---
#### Kubernetes Proxy
```
# client
kubectl proxy
# dashboard
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:443/proxy/#!/login
# grafana
http://localhost:8001/api/v1/namespaces/kube-system/services/http:monitoring-grafana:80/proxy/dashboard/db/cluster?orgId=1
# influxdb
http://localhost:8001/api/v1/namespaces/kube-system/services/monitoring-influxdb
# direct access grafana
http://192.168.1.11:30920/datasources/new
# userid / password - admin / admin
```
---
#### Deployment
* Namespace
```json
{
"kind": "Namespace",
"apiVersion": "v1",
"metadata": {
"name": "apex-stage"
}
}
```
---
* Pod deployment config
```yaml
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: us2-crm
namespace: us2-dev
spec:
selector:
matchLabels:
app: us2-crm
replicas: 2 # tells deployment to run 2 pods matching the template
template:
metadata:
labels:
app: us2-crm
spec:
containers:
- name: us2-crm
image: us2hho/vue2crm:1.0
ports:
- containerPort: 80
```
---
* Expose the app
```yaml
kubectl expose -n us2-dev deployment us2-crm \
--type=LoadBalancer --name=u2-crm-service
```
---
#### Kubernetes Port-fowarding
* port forwarding
* demo