kubernetesgoogle-kubernetes-enginegoogle-cloud-buildkubernetes-deploymentcloudbuild.yaml

Google cloud Manifest unknown during deploy to Kubernetes cluster


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


Solution

  • 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