[Book] GitOps Cookbook: 03. Containers


03.5 - Building a Container Using Shipwright and kaniko in Kubernetes


Делаю:
25.05.2023


Поставил Tekton


$ kubectl apply -f \
    https://github.com/shipwright-io/build/releases/download/v0.11.0/release.yaml


$ kubectl get pods -n shipwright-build
NAME                                          READY   STATUS    RESTARTS   AGE
shipwright-build-controller-86547f98d-4wz8b   1/1     Running   0          59s


$ kubectl apply -f \
    https://github.com/shipwright-io/build/releases/download/v0.11.0/sample-strategies.yaml


$ kubectl get cbs


$ {
    export REGISTRY_SERVER=https://index.docker.io/v1/
    export REGISTRY_USER=webmakaka
    export REGISTRY_PASSWORD=webmakaka-password
    export [email protected]

    echo ${REGISTRY_SERVER}
    echo ${REGISTRY_USER}
    echo ${REGISTRY_PASSWORD}
    echo ${EMAIL}
}


$ kubectl create secret docker-registry push-secret \
    --docker-server=${REGISTRY_SERVER} \
    --docker-username=${REGISTRY_USER} \
    --docker-password=${REGISTRY_PASSWORD} \
    --docker-email=${EMAIL}


$ kubectl get secrets
NAME          TYPE                             DATA   AGE
push-secret   kubernetes.io/dockerconfigjson   1      8s


$ cat << EOF | kubectl apply -f -
apiVersion: shipwright.io/v1alpha1
kind: Build
metadata:
  name: kaniko-nodejs-build
spec:
  source:
    url: https://github.com/shipwright-io/sample-nodejs
    contextDir: docker-build
  strategy:
    name: kaniko
    kind: ClusterBuildStrategy
  output:
    image: webmakaka/sample-nodejs:latest
    credentials:
      name: push-secret
EOF


$ kubectl get builds
NAME                  REGISTERED   REASON      BUILDSTRATEGYKIND      BUILDSTRATEGYNAME   CREATIONTIME
kaniko-nodejs-build   True         Succeeded   ClusterBuildStrategy   kaniko              21s


$ cat << EOF | kubectl create -f -
apiVersion: shipwright.io/v1alpha1
kind: BuildRun
metadata:
  generateName: kaniko-nodejs-buildrun-
spec:
  buildRef:
    name: kaniko-nodejs-build
EOF


NAME                                     READY   STATUS      RESTARTS   AGE
kaniko-nodejs-buildrun-qj8wh-7xk8s-pod   0/3     Completed   0          2m23s


$ kubectl logs -f kaniko-nodejs-buildrun-qgnct-nw46r-pod -c step-build-and-push


$ kubectl get buildruns
NAME                           SUCCEEDED   REASON   STARTTIME   COMPLETIONTIME
kaniko-nodejs-buildrun-qj8wh   True        Succeeded   22m         20m