---
# System prepended metadata

title: Development Guides
tags: [Installation]

---

# Development Guides
###### tags: `Installation`

## Outline

This is a guide that you to develop the components in the k8s cluster.

First of all, you need to install **golang**.
And you may also need to the account of [Docker hub](https://hub.docker.com/) to store your own image.

Let's get started!
- [ ] golang
- [ ] the account of Docker hub 

Please choose the version you want.

---

## Install Golang

Command
```bash=
$ wget https://lsalab.cs.nthu.edu.tw/~riya/deploy/go/install_golang.sh
$ sh ./install_golang.sh
```

Script
```bash=
#!/bin/bash

wget https://golang.org/dl/go1.14.7.linux-amd64.tar.gz
tar -C /usr/local -xzf ./go1.14.7.linux-amd64.tar.gz
echo 'export PATH="$PATH:/usr/local/go/bin"' >> ~/.bashrc
echo 'export GOPATH="$HOME"' >> ~/.bashrc
echo 'export GOBIN="$GOPATH/bin"' >> ~/.bashrc
source ~/.bashrc
mkdir -p $GOPATH/src
go version
echo $PATH
go env
```


## kubernetes in docker(kind)

If you have a existing k8s cluster that its version does not meet the requirement, you can create the k8s cluster by kind.
+ Installation

```bash=
$ wget https://lsalab.cs.nthu.edu.tw/~riya/deploy/kubernetes/kind/kind
$ chmod +x ./kind
$ mv ./kind /some-dir-in-your-PATH/kind
```

+ Creating a Cluster

**You can modify the yaml to meet the version you expected**
```bash=
$ wget https://lsalab.cs.nthu.edu.tw/~riya/deploy/kubernetes/kind/kind-config.yaml
$ sudo ./kind create cluster --name ganbatte --config kind-config.yaml
```

+ Deleting a Cluster 

```bash=
$ kind delete cluster --name Ganbatte
```

+ Recover the oringnal k8s cluster

:::warning
If you didn't want to keep the cluster of kind that you create, please delete it.
:::

```
$ sudo cp /etc/kubernetes/admin.conf ~/.kube/config 
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
$ export KUBECONFIG=$HOME/.kube/config
```

> See more: https://kind.sigs.k8s.io/docs/user/quick-start/



## kube-prometheus

Download the repository

```bash=
$ git clone https://github.com/coreos/kube-prometheus.git
$ cd kube-prometheus
```

Kubernetes compatibility matrix
![](https://i.imgur.com/XdjeCdp.png)

If you want to change the version
```bash=
$ git checkout release-0.3
```

If you want to expose the port,
you can add nodePort to the prometheus-service.yaml and grafana-service.yaml

```yaml=
apiVersion: v1
kind: Service
metadata:
  labels:
    prometheus: k8s
  name: prometheus-k8s
  namespace: monitoring
spec:
  ports:
  - name: web
    port: 9090
    targetPort: web
    nodePort: 30093
  type: NodePort
  selector:
    app: prometheus
    prometheus: k8s
  sessionAffinity: ClientIP
```
```yaml=
apiVersion: v1
kind: Service
metadata:
  labels:
    app: grafana
  name: grafana
  namespace: monitoring
spec:
  ports:
  - name: http
    port: 3000
    targetPort: http
    nodePort: 32222
  type: NodePort
  selector:
    app: grafana
```

Install
```bash=
$ kubectl create -f manifests/setup
$ kubectl create -f manifests/
```

The Defalut account & passwd: admin

> See more: https://github.com/prometheus-operator/kube-prometheus/tree/master