1

I'm trying to deploy my code placed in bitbucket repo to Kubernetes clusters available in google cloud. I've created a trigger which react when I push new changes to bitbucket repo.

I mean:

enter image description here

Based on guidance: https://cloud.google.com/build/docs/deploying-builds/deploy-gke#automating_deployments I've created: cloudbuild.yaml file with content:

steps:
  - name: "gcr.io/cloud-builders/gke-deploy"
    args:
    - run
    - --filename=${_TECH_RADAR_KUB_CONFIG_LOCATION}
    - --image=gcr.io/java-kubernetes-clusters-test/bitbucket.org/intivetechradar/technology-radar-be:${SHORT_SHA}
    - --location=${_TECH_RADAR_GKE_LOCATION}
    - --cluster=${_TECH_RADAR_CLUSTER_NAME}
    env:
      - 'SHORT_SHA=$SHORT_SHA'
options:
  logging: CLOUD_LOGGING_ONLY

In my repo I additionally I have additionally deployment.yaml file with Kuberneties config:

apiVersion: "apps/v1"
kind: "Deployment"
metadata:
  name: "java-kubernetes-clusters-test"
  namespace: "default"
  labels:
    app: "java-kubernetes-clusters-test"
spec:
  replicas: 3
  selector:
    matchLabels:
      app: "java-kubernetes-clusters-test"
  template:
    metadata:
      labels:
        app: "java-kubernetes-clusters-test"
    spec:
      containers:
        - name: "technology-radar-be-1"
          image: "gcr.io/java-kubernetes-clusters-test/bitbucket.org/intivetechradar/technology-radar-be:SHORT_SHA"

My build is starting but got stack on issue MANIFEST UNKNOWN like below: enter image description here

How can I solve this problem? Can I somehow let Kubernetes engine know that such manifest exits in additional pre step in cloudbuild.yaml file? I would be grateful for help. Thanks!

UPDATE:

I'm trying to use cloudbuild.yaml like below:

substitutions:
  _CLOUDSDK_COMPUTE_ZONE: us-central1-c  # default value
  _CLOUDSDK_CONTAINER_CLUSTER: kubernetes-cluster-test      # default value

steps:
  - id: 'build test image'
    name: 'gcr.io/cloud-builders/docker'
    args: ['build', '-t', 'gcr.io/${_TECH_RADAR_PROJECT_ID}/technology-radar-be/master:$SHORT_SHA', '.']
  - id: 'push test core image'
    name: 'gcr.io/cloud-builders/docker'
    args: ['push', 'gcr.io/${_TECH_RADAR_PROJECT_ID}/technology-radar-be/master:$SHORT_SHA:$SHORT_SHA']
  - id: 'set test core image in yamls'
    name: 'ubuntu'
    args: ['bash','-c','sed -i "s,${_TECH_CONTAINER_IMAGE},gcr.io/$PROJECT_ID/technology-radar-be/$master:$SHORT_SHA," deployment.yaml']
  - name: 'gcr.io/cloud-builders/kubectl'
    args: ['apply', '-f', 'deployment.yaml']
    env:
      - 'CLOUDSDK_COMPUTE_ZONE=${_CLOUDSDK_COMPUTE_ZONE}'
      - 'CLOUDSDK_CONTAINER_CLUSTER=${_CLOUDSDK_CONTAINER_CLUSTER}'
options:
  logging: CLOUD_LOGGING_ONLY

The last error message is: enter image description here

Is there something wrong with my Dockerfile definition? :

FROM maven:3.8.2-jdk-11 as builder
ARG JAR_FILE=target/docker-demo.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>docker-kubernetes</artifactId>
    <version>0.0.1</version>
    <name>docker-kubernetes</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <finalName>docker-demo</finalName>
    </build>
</project>

Screenshot from project tree: enter image description here

Local deployment works:

enter image description here

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
Krzysztof Michalski
  • 791
  • 1
  • 9
  • 25

1 Answers1

1

Not sure but if you look at the error it's trying to fetch the

gcr.io/java-kubernetes-clusters-test/bitbucket.org/intivetechradar/technology-radar-be/SHORT_SHA not gcr.io/java-kubernetes-clusters-test/bitbucket.org/intivetechradar/technology-radar-be:SHORT_SHA it's not using : before the TAG are you building images ?

Update :

Just tested this file with cloud build and GKE working for me : https://github.com/harsh4870/basic-ci-cd-cloudbuild/blob/main/cloudbuild-gke.yaml

However you can use the cloudbuild.yaml

substitutions:
    _CLOUDSDK_COMPUTE_ZONE: us-central1-c  # default value
    _CLOUDSDK_CONTAINER_CLUSTER: standard-cluster-1      # default value
steps:
- id: 'build test image'
  name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME/$BRANCH_NAME:$SHORT_SHA', '.']
- id: 'push test core image'
  name: 'gcr.io/cloud-builders/docker'
  args: ['push', 'gcr.io/$PROJECT_ID/$REPO_NAME/$BRANCH_NAME:$SHORT_SHA']
- id: 'set test core image in yamls'
  name: 'ubuntu'
  args: ['bash','-c','sed -i "s,TEST_IMAGE_NAME,gcr.io/$PROJECT_ID/$REPO_NAME/$BRANCH_NAME:$SHORT_SHA," deployment.yaml']
- name: 'gcr.io/cloud-builders/kubectl'
  args: ['apply', '-f', 'deployment.yaml']
  env:
  - 'CLOUDSDK_COMPUTE_ZONE=${_CLOUDSDK_COMPUTE_ZONE}'
  - 'CLOUDSDK_CONTAINER_CLUSTER=${_CLOUDSDK_CONTAINER_CLUSTER}'

deployment.yaml

apiVersion: "apps/v1"
kind: "Deployment"
metadata:
  name: "java-kubernetes-clusters-test"
  namespace: "default"
  labels:
    app: "java-kubernetes-clusters-test"
spec:
  replicas: 3
  selector:
    matchLabels:
      app: "java-kubernetes-clusters-test"
  template:
    metadata:
      labels:
        app: "java-kubernetes-clusters-test"
    spec:
      containers:
        - name: "technology-radar-be-1"
          image: TEST_IMAGE_NAME
Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • Harsh Manvar, thanks a lot for your response! What value should I put to the _BUCKET_PATH? Should it be something like: https://bitbucket.org/intivetechradar/technology-radar-be.git ? – Krzysztof Michalski Dec 10 '22 at 11:53
  • ohh sorry that's my custom thing you can ignore that whole step. you can use build and push stage only i have updated the answer, i kept for more idea you can add custom steps like that with bash. – Harsh Manvar Dec 10 '22 at 12:20
  • this single file directly deploying to cluster without even the yaml file. – Harsh Manvar Dec 10 '22 at 12:25
  • I've deleted step with `gsutil`, but I have something wrong with Dockerfile right now. Harh, could you take a look on my post update? I've added last error. – Krzysztof Michalski Dec 10 '22 at 12:30
  • sure, no worries checking that, you can also refer this https://github.com/GoogleCloudPlatform/cloud-builders/blob/master/gke-deploy/doc/trigger.yaml it has all the steps to build edit the yaml file – Harsh Manvar Dec 10 '22 at 12:31
  • check your dockrignore file which not allowing file to get copy maybe in dockerfile – Harsh Manvar Dec 10 '22 at 12:32
  • here is documentation to refer with all instruction : https://github.com/GoogleCloudPlatform/cloud-builders/blob/master/gke-deploy/doc/automated-deployments.md – Harsh Manvar Dec 10 '22 at 12:34
  • I have no .dockerignore definition in repo. As far as I know if it's not defined then google cloud uses .gitignore. That's why I have a lines this file like: target/ !target/docker-demo.jar !target/app.jar – Krzysztof Michalski Dec 10 '22 at 12:39
  • got that so you dockerfile and other file all are in root path of gitrepo right ? as build command uses the rootpath and expect everything in root path – Harsh Manvar Dec 10 '22 at 12:43
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/250308/discussion-between-krzysztof-michalski-and-harsh-manvar). – Krzysztof Michalski Dec 10 '22 at 12:46
  • feel free to update the status of question if answer resolves your issue or do upvote if found it helpful. – Harsh Manvar Jan 18 '23 at 12:57