CI/CD on Kubernetes.
- GKE - Google Container Engine is a Managed Kubernetes offering from Google
- Jenkins X - Jenkins X is a CI/CD solution for modern cloud applications on Kubernetes
- Overall Agenda is to demonstrate GitOps
- Development > Staging > Production
- Install Jenkins X on Google Container Engine
- Enable Managed Istio (when avaiable)
- Deploy sample golang application to staging environment
- Deploy sample golang application to production environment
- Google Compute Platform Account
- A project on Google Compute Platform
- Github Account
Jenkins X : https://jenkins-x.io/getting-started/create-cluster/
gcloud link : https://cloud.google.com/sdk/docs/#deb
Do not use Google Cloud Shell as it does not have persistence.
In your local linux shell :
Download the jx binary
curl -L https://github.com/jenkins-x/jx/releases/download/v1.3.110/jx-linux-amd64.tar.gz | tar xzv
sudo mv jx /usr/local/bin
Create a GKE Cluster
jx create cluster gke --skip-login -n au-jx-cluster
Options to select :
-
Select
helm
and orkubectl
to be installed -
Google Cloud Zone:
australia-southeast1-a
-
Google Cloud Machine Type:
n1-standard-2
-
Minimum number of Nodes :
3
-
Maximum number of Nodes :
5
-
Git configured for user:
jamesbuckett
-
Git email configured for user: :
[email protected]
-
No existing ingress controller found : Y
Lets set up a git username and API token to be able to perform CI/CD
- GitHub user name:
jamesbuckett
Link : https://github.com/settings/tokens/new?scopes=repo,read:user,read:org,user:email,write:repo_hook,delete_repo
- API Token:
xxxxxxxxxxxxxxxxxxx
NOTE: Your admin password is: xxxxxx
To get API token go to : http://jenkins.jx.x.x.x.x.nip.io/me/configure
-
User :
admin
-
NOTE: Your admin password is:
xxxxxx
To import existing projects into Jenkins: `jx import`
To create a new Spring Boot microservice: `jx create spring -d web -d actuator`
To create a new microservice from a quickstart: `jx create quickstart`
- Jenkins provides both CI and CD automation.
- Nexus acts as a dependency cache for Nodejs and Java applications to dramatically improve build times.
- After an initial build of a SpringBoot application the build time is reduced from 12 mins to 4.
- JFrog Artifactory support is planned.
- Docker registry an in cluster docker registry where pipelines push application images.
- Plan to switch to using native cloud provider registries such as
- Google Container Registry
- Azure Container Registry
- Amazon Elastic Container Registry
- Chartmuseum is a registry for publishing Helm charts
- Monocular is a UI used for discovering and running Helm charts
- Helm is a tool for managing Kubernetes charts. Charts are packages of pre-configured Kubernetes resources.
- Skaffold builds Docker Images and redeploys the images.
- Skaffold is a command line tool that facilitates continuous development for Kubernetes applications.
- You can iterate on your application source code locally then deploy to local or remote Kubernetes clusters.
- Skaffold handles the workflow for building, pushing and deploying your application.
- It can also be used in an automated context such as a CI/CD pipeline to leverage the same workflow and tooling when moving applications to production.
- Kaniko is a tool to build container images from a Dockerfile, inside a container or Kubernetes cluster.
- Kaniko doesn't depend on a Docker daemon and executes each command within a Dockerfile completely in userspace.
- This enables building container images in environments that can't easily or securely run a Docker daemon, such as a standard Kubernetes cluster.
- Ksync speeds up developers who build applications for Kubernetes.
- It transparently updates containers running on the cluster from your local checkout.
- This enables developers to use their favorite IDEs, such as Atom or Sublime Text to work from inside a cluster instead of from outside it.
- http://jenkins.jx.x.x.x.X.nip.io
- User: admin
- Pass: In output of install
- Promote : Never
- Namespace : jx
- Jenkins Master
- Elastic pool of Kubernetes Build Pods
- Nexus and Monocular (helm application store)
- Promote : Auto
- Namespace : jx-staging
- Jenkins Master
- Elastic pool of Kubernetes Build Pods
- Nexus and Monocular (helm application store)
- Promote : Manual
- Namespace : jx-production
- Jenkins Master
- Elastic pool of Kubernetes Build Pods
- Nexus and Monocular (helm application store)
tl;dr - Weaveworks provides container management and microservices in a simple, portable and resilient way to network.
Connect a Cluster
Instance Name : gke-jx
Team : wc-team
Install..Select a Platform..Kubernetes..Google Container Engine
Install the Weave Cloud Agents
In Cloud Shell or Linux Shell
sudo apt-get install kubectl
(if local Linux Shell)
curl -Ls https://get.weave.works |
sh -s -- --token=xxxxxxxxxxxxxxxxxxxxxx --gke
jx create quickstart
Select : golang-http
Project Name : gke-jx-golang-http
Use jamesbuckett as git user name : Y
Initialize git now : Y
Commit message: Initial import
Which organisation do you want to use : jamesbuckett
Enter the new repository name: gke-jx-golang-http
Watch pipeline activity via: jx get activity -f gke-jx-golang-http -w
Browse the pipeline log via: jx get build logs jamesbuckett/gke-jx-golang-http/master
Open the Jenkins console via jx console
You can list the pipelines via: jx get pipelines
When the pipeline is complete: jx get applications
Development Environment : Link : https://github.com/jamesbuckett/gke-jx-golang-http
Look for the main.go
file which prints a message to the screen.
package main
import (
"fmt"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
title := "Jenkins X golang http example"
from := ""
if r.URL != nil {
from = r.URL.String()
}
if from != "/favicon.ico" {
log.Printf("title: %s\n", title)
}
fmt.Fprintf(w, "Hello from: "+title+"\n")
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
Get Jenkins X environments
- jx get env
kubectl create clusterrolebinding cluster-admin-binding \
--clusterrole=cluster-admin \
--user=$(gcloud config get-value core/account)
End of Section