');

Deploy the Application to an Oracle Managed Kubernetes Cluster

To deploy your container to an Oracle Container Engine for Kubernetes cluster, upload the image to a registry and then create a deployment manifest file that describes the deployment to the Oracle Container Engine for Kubernetes cluster.

Upload the Docker Image to Oracle Cloud Infrastructure Registry

The Oracle Cloud Infrastructure Registry is a private registry on which you can store your application images. You can use any registry for this purpose as long as your cloud infrastructure can access it.

To upload your image to Oracle Cloud Infrastructure Registry, you need to tag it appropriately and then upload it to the registry. To upload an image on to Oracle Cloud Infrastructure Registry, specify the fully qualified path to the target location in Oracle Cloud Infrastructure Registry where you want to upload the image, optionally including the name of a repository. Here, you've tagged it already with the Docker plugin for gradle, by specifying the tag name in build.gradle.

tag = 'data-region.ocir.io/my-tenant/my-repo/omc-sample-app:latest'

Once the image is ready to be uploaded to Oracle Cloud Infrastructure Registry, sign in to the Oracle Cloud Infrastructure console to set up an access token in Oracle Cloud Infrastructure. The access token helps you to sign in to Oracle Cloud Infrastructure using the Docker command-line interface (CLI).

  1. In the Oracle Cloud Infrastructure console, in the top-right corner, click User menu and then click User Settings to view the details.
  2. On the Auth Tokens page, click Generate Token.
  3. In the Generate Token dialog box, enter a friendly description for the authentication token and click Generate Token. The new authentication token is displayed.
  4. Copy the authentication token to a secure location from where you can retrieve it later, because you won't see the authentication token again in the Oracle Cloud Infrastructure console.
  5. Close the Generate Token dialog box and close the Oracle Cloud Infrastructure console.


After creating the authentication token, upload your image to Oracle Cloud Infrastructure Registry.

  1. Sign in to Oracle Cloud Infrastructure using the standard Docker CLI.

    docker login data-region.ocir.io

  2. Enter your user name in the format, my-tenant/username@example.com. When prompted, enter the authentication token that you saved earlier.
  3. Upload your image to Oracle Cloud Infrastructure Registry.

    docker push data-region.ocir.io/my-tenant/my-repo/omc-sample-app

Once uploaded, you can view the image in your repository.



Deploy the Application to an Oracle Container Engine for Kubernetes Cluster

After uploading the image, you need to set up your Kubernetes deployment manifest to manage your application as a deployment unit, and then deploy the Kubernetes cluster.

This manifest describes a Deployment object that needs to have one replica based on the image that you created.

  1. Create a manifest file, omc-sample-svc.yaml , in your current directory similar to the following.
    apiVersion: apps/v1
    kind: Deployment
    metadata: 
    name: omc-sample-app
    spec: 
    selector: 
        matchLabels:
        app: omc-sample-app
    replicas: 1
    template:
        metadata:
        labels: 
            app: omc-sample-app
        spec:
        containers:
        - name: omc-sample-app
            image: data-region.ocir.io/my-tenant/my-repo/omc-sample-app:latest 
            ports:
            - containerPort: 8080
    ---
    apiVersion: v1
    kind: Service
    metadata:
    name: omc-sample-app
    spec:
    selector:
        app: omc-sample-app
    ports:
    - protocol: "TCP"
        port: 8080
        targetPort: 8080
    type: LoadBalancer
    

    The deployment is named omc-sample-app, which creates the application containers. To enable access to the deployment as a whole, you create a service, which in this case is of type LoadBalancer. When deployed, this automatically provisions an Oracle Cloud Infrastructure Load Balancing instance to manage and route traffic to the application.

  2. Deploy the application images by running kubectl from your current directory.

    kubectl apply -f omc-sample-svc.yaml