CODEFRESH.IO DOCUMENTATION

Codefresh is a Docker-native CI/CD platform.
Instantly build, test and deploy Docker images.

GET STARTED

Search results for "{{ search.query }}"

No results found for "{{search.query}}". 
View All Results

Google Container Engine (GKE) - Kubernetes

Google Container Engine is a powerful cluster manager and orchestration system for running your Docker containers built on Kubernetes. Deploying to GKE will follow the standard Kubernetes steps outlined below.

Getting Started

The first step will be to make sure that your Kubernetes master is up.
Login to https://console.cloud.google.com with your Google Credentials.

Enter to Containers Engine and make sure you have created GKE cluster.

get your cluster username and password from GKE -> Container Cluster -> <your cluster> -> show credentials

To be able to test your deployment on local environment configure gcloud and kubectl utilities
https://cloud.google.com/sdk/downloads
https://kubernetes.io/docs/tasks/kubectl/install/

To connect to your cluster from your machine:

gcloud container clusters get-credentials <clusre-name>   --zone <gce-zone> --project <project-name>

For example:

gcloud container clusters get-credentials kube-demo-oleg --zone asia-east1-b --project kuberentes

Then create deployment.yml for your app http://kubernetes.io/docs/user-guide/deployments and test it by running :

kubectl apply -f deployment.yml

Deploy to GKE from Codefresh pipeline

The deployment script makes the following assumptions about your application and Kubernetes configuration:

  • The application is deployed using the Kubernetes deployment API (versus the the replication controller directly). For more information read http://kubernetes.io/docs/user-guide/deployments/
  • The tested codebase has a yaml file that describes the Kubernetes deployment parameters and configuration of your application.
  • At the moment, only the basic username/pass authentication is supported.

Deploy to Kubernetes

Edit codefresh.yml and deployment.yml.tmpl files.

version: '1.0'

steps:
  build:
    type: build
    dockerfile: Dockerfile
    image_name: myrepo/apisvc
    tag: '${{CF_BRANCH}}'
    
  push:
    type: push
    candidate: ${{build}}
    tag: ${{CF_BRANCH}}

  deploy-to-kubernetes:
    image: codefresh/cf-deploy-kubernetes:latest
    working-directory: ${{main_clone}}
    commands:
      - /cf-deploy-kubernetes deployment.yml.tmpl
    environment:
      - KUBERNETES_USER=${{KUBERNETES_USER}}
      - KUBERNETES_PASSWORD=${{KUBERNETES_PASSWORD}}
      - KUBERNETES_SERVER=${{KUBERNETES_SERVER}}
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: api-svc
spec:
  replicas: 1
  template:
    metadata:
      annotations:
        revision: "{{CF_REVISION}}"
      labels:
        app: api-svc
    spec:
      containers:
        - name: apisvc
          image: myrepo/apisvc:{{CF_BRANCH}}
          ports:
            - containerPort: 80
              name: http

Set up the following environment variables to specify the Kubernetes cluster we'll use to deploy the project.

Variable
Description

KUBERNETES_USER

The user for the Kubernetes cluster. Mandatory.

KUBERNETES_PASSWORD

The password for the Kubernetes cluster. Mandatory.

KUBERNETES_SERVER

The server (HTTPS endpoint) of the Kubernetes cluster's API. Mandatory.

  1. Run the build in Codefresh.io
  2. Check that the deployment succeeded with kubectl:
kubectl get pods -l app=alpine-nginx

Google Container Engine (GKE) - Kubernetes