kubernetes-rancher-cd-pipeline.md 2.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
---
date: 2019-07-17T00:00:00+01:00
title: Kubernetes-Rancher CI/CD Pipeline
author: pcdummy
tags:
  - HOWTO
  - Kubernetes
  - Rancher
  - CI/CD
René Jochum's avatar
René Jochum committed
10
  - My Blog
11
---
René Jochum's avatar
Large I    
René Jochum committed
12
Today I moved my [gohugo.io](https://gohugo.io/) blog from a lxd hosting to our Kubernetes -dev Cluster at the [Webmeisterei](https://webmeisterei.com).
13

René Jochum's avatar
Large I    
René Jochum committed
14
We have our own [Gitlab](https://git.webmeisterei.com) so and we run our own registry on the -dev Cluster, I thought it will be easy to do so but it wasn't that easy and I lost about 8 Hours until I found out that had to open the required Ports on the Firewall :).
René Jochum's avatar
René Jochum committed
15
16

See this works.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!--more-->

#### Tools in use

- [Rancher](https://rancher.com/) 2.x for Kubernetes with RBAC, Metrics, Logging and much more.
- [Gitlab](https://about.gitlab.com/) on-premises alternative to github.com
- [Harbor](https://goharbor.io/) not yet in use but will be soon our container registry
- [cert-manager](https://github.com/jetstack/cert-manager)
- [Let's Encrypt](https://letsencrypt.org/) Let's Encrypt

#### The Docker Container

I use a [multi-stage build](https://docs.docker.com/develop/develop-images/multistage-build/) to generate the page in a container and serve a copy of the page after in a nginx container.

See this [Dockerfile](https://git.webmeisterei.com/jochum/rene.jochums.at/blob/master/Dockerfile)

```bash
# Build public with hugo
FROM jguyomard/hugo-builder:latest

COPY . /build

WORKDIR /build

RUN hugo -b https://rene.jochums.at -v -t persona

# Copy to a nginx container
FROM nginx:1.17-alpine

COPY docker/nginx/nginx.conf /etc/nginx/
COPY docker/nginx/default.conf /etc/nginx/conf.d/

# This is important "COPY --from=0" line where --from=0 means copy from the first container.
COPY --from=0 /build/public /var/www/rene.jochums.at
```

#### The Deployment

René Jochum's avatar
Large I    
René Jochum committed
55
With lots of try-and-error testing I got this [deployment.yaml](https://git.webmeisterei.com/jochum/rene.jochums.at/blob/master/deployment.yaml) together.
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

Its important that you have to add the registry to your Project first, in this case **registry.dev.wmk8s.com**.


#### And the pipeline itself

The last step after the container and the deployment was to create a .rancher-pipeline.yml in my repo, I used Rancher -> Cluster dev -> Project -> Workloads -> Pipelines to generate it.

```yaml
stages:
- name: Build
  steps:
  - publishImageConfig:
      dockerfilePath: ./Dockerfile
      buildContext: .
      tag: pcdummy/renejochumsat:latest
      pushRemote: true
      registry: registry.dev.wmk8s.com
- name: Deploy
  steps:
  - applyYamlConfig:
      path: ./deployment.yaml
timeout: 60
notification:
  recipients:
  - recipient: rene@webmeisterei.com
    notifier: local:n-mtzwd
  condition:
  - Success
  - Changed
  - Failed
```
René Jochum's avatar
René Jochum committed
88
89
90
91

#### If it doesn't trigger

Look at [this](https://forums.rancher.com/t/pipeline-not-triggering/12691/5) if it doesn't trigger your build.