Skip to content

Commit

Permalink
multiple configuration examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tirumaraiselvan committed May 25, 2018
1 parent 405d39a commit 1e2698a
Show file tree
Hide file tree
Showing 24 changed files with 580 additions and 158 deletions.
4 changes: 0 additions & 4 deletions Dockerfile

This file was deleted.

101 changes: 46 additions & 55 deletions README.md
@@ -1,59 +1,50 @@
# gitkube-example
# gitkube-examples

An nginx example application to be used with [gitkube](https://github.com/hasura/gitkube): git push to deploy on to Kubernetes.

## Instructions

- Install [gitkube](https://github.com/hasura/gitkube) on your Kubernetes cluster
```sh
$ kubectl create -f https://storage.googleapis.com/gitkube/gitkube-setup-stable.yaml

$ #expose gitkubed service
$ kubectl --namespace kube-system expose deployment gitkubed --type=LoadBalancer --name=gitkubed
```
- Clone this repo:
```bash
$ git clone https://github.com/hasura/gitkube-example
$ cd gitkube-example
```
- Create a kubernetes deployment and service:
```bash
$ kubectl create -f k8s.yaml
```
- Add your SSH public key to `remote.yaml`:
```bash
$ cat ~/.ssh/id_rsa.pub | awk '$0=" - "$0' >> "remote.yaml"
```
- [Multi-node] If you are running a multi-node cluster, `remote.yaml` should specify a `registry` to push and pull from/into the cluster. Read more about this secret [here](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/) and detailed instructions for few registry providers [here](https://github.com/hasura/gitkube/blob/master/docs/registry.md).
```sh
registry:
url: "docker.io/<user>"
credentials:
# docker-registry secret name
secretRef: regsecret
```

- Create the gitkube remote:
```bash
$ kubectl create -f remote.yaml
```
- Wait for the remote url:
```bash
$ kubectl get remote example -o json | jq -r '.status.remoteUrl'
# remoteUrl will be like ssh://default-example@[ip-address]/~/git/default-example
```
Note that for services exposed as type NodePort, `remoteUrl` will not be filled automatically. Check `.status.remoteUrlDesc` for instructions on manually constructing the `remoteUrl`
- Create the git remote:
```bash
$ git remote add example [remoteUrl]
```
- Git push to update the nginx application
```bash
$ git push example master
```
- Checkout the application using kubectl proxy:
```bash
$ kubectl proxy
```
Visit http://localhost:8001/api/v1/namespaces/default/services/nginx/proxy on browser
## Installation instructions

### Using kubectl

```sh
kubectl create -f https://storage.googleapis.com/gitkube/gitkube-setup-stable.yaml

#expose gitkubed service
kubectl --namespace kube-system expose deployment gitkubed --type=LoadBalancer --name=gitkubed
```

### Using gitkube CLI

1. Install Gitkube CLI:
- Linux/MacOS
``` bash
curl https://raw.githubusercontent.com/hasura/gitkube/master/gimme.sh | bash
```
- Windows: download the latest [release](https://github.com/hasura/gitkube/releases) and add it to your `PATH`.

2. Use Gitkube CLI to install Gitkube on the cluster:
```bash
gitkube install
```

## Repository configuration

Gitkube works with whatever kind of repository configurations you prefer. Here are some common configurations:

#### Mono-repo

Your git repo contains configuration + code for your entire application including all your microservices and k8s manifests.

Follow the instructions for mono-repo setups below:

- [Mono-repo with K8s yamls and microservices](mono-repo/README.md)
- [Mono-repo with Helm chart and microservices](mono-repo-helm/README.md)

#### Multi-repo

You have separate repos for your configuration and microservices.

Follow the instructions for multi-repo setup below:

- [Multi-repo with K8s yamls in one repo and microservices in another repo](multi-repo/README.md)

37 changes: 0 additions & 37 deletions html/index.html

This file was deleted.

41 changes: 0 additions & 41 deletions k8s.yaml

This file was deleted.

72 changes: 72 additions & 0 deletions mono-repo-helm/README.md
@@ -0,0 +1,72 @@
# Mono-repo-helm

Install `gitkube` cli as per [this](../README.md)

1. Download this repo and unzip it to a path

```
$ wget https://github.com/hasura/gitkube-example/archive/master.zip
$ unzip master.zip
$ mv gitkube-example-master gitkube-examples
```
2. Goto `mono-repo-helm` directory and initialise a repo

```
$ cd gitkube-examples/mono-repo-helm
$ git init
```

3. Generate a Remote spec

```
$ gitkube remote generate -f myremote.yaml
> Remote name: myremote
> Namespace: default
> Public key file: /home/tselvan/.ssh/id_rsa.pub
> Initialisation:
> K8s Yaml Manifests
> Helm Chart
--------------------
> None
> Manifests/Chart directory: mychart
> Choose docker registry:
> docker.io/tirumarai
---------------------
> Specify a different registry
> Skip for now
> Deployment name: www
> Container name: www
> Dockerfile path: microservices/nginx/Dockerfile
> Build context path: microservice/nginx
> Add another container? N
> Add another deployment? N
```
4. Edit the Remote spec to add helm release name

```
$ # Open myremote.yaml in any text editor
$ vim myremote.yaml
$ # Edit the manifests section to the following
...
manifests:
helm:
release: myapp
path: mychart
...
```

5. Create the Remote

```
$ gitkube remote create -f myremote.yaml
```

6. Git push

```
$ git commit -am "mono repo helm"
$ git push myremote master
```
7 changes: 7 additions & 0 deletions mono-repo-helm/microservices/nginx/Dockerfile
@@ -0,0 +1,7 @@
FROM nginx:latest

#Copy the configuration
COPY app/conf/nginx.conf /etc/nginx

#Copy the static files to be served
COPY app/src/ /usr/share/nginx/html
44 changes: 44 additions & 0 deletions mono-repo-helm/microservices/nginx/app/conf/nginx.conf
@@ -0,0 +1,44 @@
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;

server {
listen 8080;
server_name localhost;

location / {
root /usr/share/nginx/html;
}
}
}




10 changes: 10 additions & 0 deletions mono-repo-helm/microservices/nginx/app/src/index.html
@@ -0,0 +1,10 @@
<html>
<head><title>git push a helm app</title></head>
<body style="display: flex; align-items: center; justify-content: center; font-family: sans-serif; color: #333;">
<h1>
Hi!<br/>
I came from a Dockerfile,<br/>
configured by a Helm chart.
</h1>
</body>
</html>
5 changes: 5 additions & 0 deletions mono-repo-helm/mychart/Chart.yaml
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for my application
name: mychart
version: 0.1.0
29 changes: 29 additions & 0 deletions mono-repo-helm/mychart/templates/deployment.yaml
@@ -0,0 +1,29 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: www
hasuraService: custom
name: www
namespace: helm
spec:
replicas: 1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: www
spec:
containers:
- image: hasura/base-git-image:0.7
imagePullPolicy: IfNotPresent
name: www
ports:
- containerPort: 8080
protocol: TCP
resources: {}
securityContext: {}
terminationGracePeriodSeconds: 0
status: {}
19 changes: 19 additions & 0 deletions mono-repo-helm/mychart/templates/service.yaml
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: www
hasuraService: custom
name: www
namespace: helm
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8080
selector:
app: www
type: LoadBalancer
status:
loadBalancer: {}

0 comments on commit 1e2698a

Please sign in to comment.