diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 95f4a47..0000000 --- a/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM nginx:stable-alpine - -# Copy the static files to be served -COPY html/ /usr/share/nginx/html diff --git a/README.md b/README.md index 079675c..6722ae0 100644 --- a/README.md +++ b/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/" - 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) diff --git a/html/index.html b/html/index.html deleted file mode 100644 index 158f537..0000000 --- a/html/index.html +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - Gitkube Example - - - -
-

Yay!

-

Successfully deployed using Gitkube

-

You have successfully deployed your first application on to a Kubernets cluster using Gitkube.

-

To deploy any further changes to this application, all you need do to is to make the change, commit and push again

- - $ git add [files]
- $ git commit -m "[message]"
- $ git push [remote] master
-
-
-
- - diff --git a/k8s.yaml b/k8s.yaml deleted file mode 100644 index 78c387b..0000000 --- a/k8s.yaml +++ /dev/null @@ -1,41 +0,0 @@ -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - labels: - app: nginx - name: nginx - namespace: default -spec: - replicas: 1 - template: - metadata: - labels: - app: nginx - spec: - containers: - - image: nginx - imagePullPolicy: IfNotPresent - name: nginx - ports: - - containerPort: 80 - protocol: TCP - resources: - requests: - cpu: 50m - memory: 100Mi ---- -apiVersion: v1 -kind: Service -metadata: - labels: - app: nginx - name: nginx - namespace: default -spec: - ports: - - port: 80 - protocol: TCP - targetPort: 80 - selector: - app: nginx - type: ClusterIP diff --git a/mono-repo-helm/README.md b/mono-repo-helm/README.md new file mode 100644 index 0000000..09dc13c --- /dev/null +++ b/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 + +``` diff --git a/mono-repo-helm/microservices/nginx/Dockerfile b/mono-repo-helm/microservices/nginx/Dockerfile new file mode 100644 index 0000000..ed58acb --- /dev/null +++ b/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 diff --git a/mono-repo-helm/microservices/nginx/app/conf/nginx.conf b/mono-repo-helm/microservices/nginx/app/conf/nginx.conf new file mode 100644 index 0000000..c1c5a03 --- /dev/null +++ b/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; + } + } +} + + + + diff --git a/mono-repo-helm/microservices/nginx/app/src/index.html b/mono-repo-helm/microservices/nginx/app/src/index.html new file mode 100644 index 0000000..cdf36bf --- /dev/null +++ b/mono-repo-helm/microservices/nginx/app/src/index.html @@ -0,0 +1,10 @@ + + git push a helm app + +

+ Hi!
+ I came from a Dockerfile,
+ configured by a Helm chart. +

+ + diff --git a/mono-repo-helm/mychart/Chart.yaml b/mono-repo-helm/mychart/Chart.yaml new file mode 100644 index 0000000..1a4c271 --- /dev/null +++ b/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 diff --git a/mono-repo-helm/mychart/templates/deployment.yaml b/mono-repo-helm/mychart/templates/deployment.yaml new file mode 100644 index 0000000..b3ce49f --- /dev/null +++ b/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: {} diff --git a/mono-repo-helm/mychart/templates/service.yaml b/mono-repo-helm/mychart/templates/service.yaml new file mode 100644 index 0000000..6ad1dc6 --- /dev/null +++ b/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: {} diff --git a/mono-repo/README.md b/mono-repo/README.md new file mode 100644 index 0000000..1f82e70 --- /dev/null +++ b/mono-repo/README.md @@ -0,0 +1,58 @@ +# Mono-repo + +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` directory and initialise a repo + +``` +$ cd gitkube-examples/mono-repo +$ 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: manifests +> 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. Create the Remote + +``` +$ gitkube remote create -f myremote.yaml +``` + +5. Git push + +``` +$ git commit -am "mono repo" +$ git push myremote master + +``` diff --git a/mono-repo/manifests/nginx-deployment.yaml b/mono-repo/manifests/nginx-deployment.yaml new file mode 100644 index 0000000..4aad695 --- /dev/null +++ b/mono-repo/manifests/nginx-deployment.yaml @@ -0,0 +1,29 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + creationTimestamp: null + labels: + app: www + hasuraService: custom + name: www + namespace: default +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: {} diff --git a/mono-repo/manifests/nginx-svc.yaml b/mono-repo/manifests/nginx-svc.yaml new file mode 100644 index 0000000..040e037 --- /dev/null +++ b/mono-repo/manifests/nginx-svc.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + creationTimestamp: null + labels: + app: www + hasuraService: custom + name: www + namespace: default +spec: + ports: + - port: 80 + protocol: TCP + targetPort: 8080 + selector: + app: www + type: LoadBalancer +status: + loadBalancer: {} diff --git a/mono-repo/microservices/nginx/Dockerfile b/mono-repo/microservices/nginx/Dockerfile new file mode 100644 index 0000000..ed58acb --- /dev/null +++ b/mono-repo/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 diff --git a/mono-repo/microservices/nginx/app/conf/nginx.conf b/mono-repo/microservices/nginx/app/conf/nginx.conf new file mode 100644 index 0000000..c1c5a03 --- /dev/null +++ b/mono-repo/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; + } + } +} + + + + diff --git a/mono-repo/microservices/nginx/app/src/index.html b/mono-repo/microservices/nginx/app/src/index.html new file mode 100644 index 0000000..03d2eec --- /dev/null +++ b/mono-repo/microservices/nginx/app/src/index.html @@ -0,0 +1,11 @@ + + git push a helm app + +

+ Hi!
+ I came from a Dockerfile,
+ configured by kubernetes manifests,
+ in a monorepo. +

+ + diff --git a/multi-repo/README.md b/multi-repo/README.md new file mode 100644 index 0000000..c789acb --- /dev/null +++ b/multi-repo/README.md @@ -0,0 +1,70 @@ +# Multi-repo + +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 +``` + +## Configuration repo + +1. Goto `multi-repo` directory and initialise the configuration repo + +``` +$ cd gitkube-examples/multi-repo/config +$ git init +``` + +## Microservices repo + +1. Goto `multi-repo` directory and initialise the configuration repo + +``` +$ cd gitkube-examples/multi-repo/nginx +$ git init +``` + + +2. 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 + ------ +> Choose docker registry: + > docker.io/tirumarai + --------------------- + > Specify a different registry + > Skip for now +> Deployment name: www +> Container name: www +> Dockerfile path: Dockerfile +> Build context path: . +> Add another container? N +> Add another deployment? N +``` + +3. Create the Remote + +``` +$ gitkube remote create -f myremote.yaml +``` + +4. Git push + +``` +$ git commit -am "multi repo" +$ git push myremote master +``` + diff --git a/multi-repo/config/nginx-deployment.yaml b/multi-repo/config/nginx-deployment.yaml new file mode 100644 index 0000000..63e8675 --- /dev/null +++ b/multi-repo/config/nginx-deployment.yaml @@ -0,0 +1,29 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + creationTimestamp: null + labels: + app: www + hasuraService: custom + name: www + namespace: multi +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: {} diff --git a/multi-repo/config/nginx-service.yaml b/multi-repo/config/nginx-service.yaml new file mode 100644 index 0000000..206f51a --- /dev/null +++ b/multi-repo/config/nginx-service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + creationTimestamp: null + labels: + app: www + hasuraService: custom + name: www + namespace: multi +spec: + ports: + - port: 80 + protocol: TCP + targetPort: 8080 + selector: + app: www + type: LoadBalancer +status: + loadBalancer: {} diff --git a/multi-repo/nginx/Dockerfile b/multi-repo/nginx/Dockerfile new file mode 100644 index 0000000..ed58acb --- /dev/null +++ b/multi-repo/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 diff --git a/multi-repo/nginx/app/conf/nginx.conf b/multi-repo/nginx/app/conf/nginx.conf new file mode 100644 index 0000000..c1c5a03 --- /dev/null +++ b/multi-repo/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; + } + } +} + + + + diff --git a/multi-repo/nginx/app/src/index.html b/multi-repo/nginx/app/src/index.html new file mode 100644 index 0000000..5764fd7 --- /dev/null +++ b/multi-repo/nginx/app/src/index.html @@ -0,0 +1,11 @@ + + git push a helm app + +

+ Hi!
+ I came from a Dockerfile,
+ Configured by kubernetes manifests,
+ In a different repo +

+ + diff --git a/remote.yaml b/remote.yaml deleted file mode 100644 index 079cc30..0000000 --- a/remote.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: gitkube.sh/v1alpha1 -kind: Remote -metadata: - name: example - namespace: default -spec: - ## uncomment to add a registry - # registry: - # url: "registry.io/user-name" - # credentials: - # secretKeyRef: - # name: regsecret - # key: .dockercfg - deployments: - - name: nginx - containers: - - name: nginx - path: . - dockerfile: Dockerfile - authorizedKeys: - - "ssh-rsa "