TheKoguryo's Tech Blog

Version 2023.04.29

Warning

This content has been generated by machine translation. The translations are automated and have not undergone human review or validation.

8.1 Deploying containers with Container Instances

OCI Container Instances

Container Orchestration is commonly used with Kubernetes to consume container applications. Alternatively, you can simply run containers by directly installing Docker Engine on a virtual machine. At this time, the user must manage Kubernetes or Docker Engine. Container Instances are managed by cloud service providers, not by users of Container Orchestration. Users can simply deploy and use containers, and have the advantage of only paying for the resources directly used by containers.

Just as one host is virtualized to provide an independent environment between VMs, a host is virtualized to provide an independent environment for Container Instance, and Container Instance provides a container runtime environment, which is managed by OCI. Users only need to manage the containers that will run on Container Instance. Please refer to the OCI First Principles video blog post for detailed inner workings.

image-20221211185818382

As seen in the GA blog of OCI Container Instances, I think it would be good to distribute and use an open source package solution that can be independently distributed and used.

Deploying WordPress and MySQL containers

You can deploy container applications through the Container Instances service.

The current GA does not support persistent volumes as of the December 2022 version. When Container Instance is restarted, data is not saved, so you will proceed from the initial installation of WordPress.

Persistent Volume is scheduled to be supported in the future.

  1. Log in to the OCI console.

  2. From the hamburger menu on the top left, go to Developer Services > Containers & Artifacts > Container Instances.

  3. Click the Create container instance button to create it.

  4. Enter basic creation information.

    • Name: ex) wordpress

    • Compartment: Select the Compartment to use

    • Placement: You can select Availability Domain and Fault Domain where the instance will be located. Use the default on a single AD basis.

    -Shape:

    • Select a shape provided for Container Instance. Flex type lets you choose the OCPU and memory size you want. This is the sum of resources used by containers in Container Instance. Here, WordPress and MySQL are used by two containers.
    • Select 2 OCPU, 16 GB memory.

    image-20221209215916712

    • Networking

      • Select the VCN and Subnet where the container instance will be located. Here, select Public Subnet for testing and assign Public IP.

      image-20221209220208921

      • You can configure advanced network settings in Show advanced options. You can set a private IP and private domain name to use when accessing container instances from the internal network.

      image-20221209220914591

      • You can specify additional advanced settings by clicking Show advanced options at the bottom of the screen. You can set the Graceful shutdown timeout and Container Restart Policy to wait when the container shuts down.

      image-20221209221612279

  5. Click Next

  6. Enter container information to run within Container Instance.

  7. Enter the MySQL container information as the first container.

    • Name: ex) mysql

    • Image: Click Select Image.

      image-20221209222538344

      • Supports OCIR and external container registries. The default server for external registries is Docker Hub. Import the MySQL image using the image name and tag as shown below.

        image-20221209222749000

    • Environmental variables: Among the environment variable values provided by the MySQL container image you are using, add the variables below required for database installation.

    KeyValue
    MYSQL_DATABASEwordpress
    MYSQL_ROOT_PASSWORDwordpressonmysql
    MYSQL_USERwordpress
    MYSQL_PASSWORDwordpress

    image-20221209223150966

    • You can specify additional advanced settings by clicking Show advanced options.

      -Resources

      If there are multiple containers in Container Instance, you can set throttling so that one container does not use resources unilaterally. You can directly specify OCPU, Memory, or set the percentage as shown in the figure below. Here, both are entered as 50%.

      image-20221209224253663

      -Startup Options

      You can set the values to use when starting the container. Starting from MySQL 8, the default authentication method has been changed. For convenience, --default-authentication-plugin=mysql_native_password is added to the ENTRYPOINT value to use the existing password method.

      image-20221209223836558

  8. Click + Add container to add a second container.

  9. Enter the wordpress container information as the second container.

    • Name: ex) wordpress

    -Image:

    Click Select Image to import from an external registry, Docker Hub, same as before. Enter only the image name in wordpress. If the tag is not present, the tag defaults to latest.

    image-20221209224802042

-Environmental variables:

  Among the environment variable values provided by the MySQL container image you are using, add the following variables required to install the database. When there are multiple containers in Container Instances, they share CPU, memory, and share the network together. So even if WORDPRESS_DB_HOST is set to 127.0.0.1, you can access the MySQL container created earlier.

 | Key                   | Value     |
 | :-------------------- | :-------- |
 | WORDPRESS_DB_HOST     | 127.0.0.1 |
 | WORDPRESS_DB_NAME     | wordpress |
 | WORDPRESS_DB_USER     | wordpress |
 | WORDPRESS_DB_PASSWORD | wordpress |

  ![image-20221209225132905](images/image-20221209225132905.png)

- You can specify additional advanced settings by clicking **Show advanced options**.

  - Resources

    The second container also sets throttling. Specify the percentage as the remaining 50% as shown in the figure below.

    ![image-20221209225259850](images/image-20221209225259850.png)
  1. Click Next

  2. Check all the information you have entered and click the Create button to create a Container Instance. Two containers, including Wordpress and MySQL to be used by Wordpress, are created as one Container Instance.

  3. After a few seconds, the Container Instance is created as shown below. Check the Public IP of the created Wordpress.

    image-20221211175434035

  4. In order to access, you must register in advance in Ingress that can be accessed from the Internet through port 80 in the Security List used by Container Instance.

    StatelessSourceIP ProtocolSource Port RangeDestination Port RangeDescription
    No0.0.0.0/0TCPAll80Wordpress
  5. You can see the initial installation screen of Wordpress by connecting to Public IP.

    image-20221209230504981

Monitoring & Log check

  1. In the Container Instance detail screen, you can see the CPU, Memory, and Storage metric information in Resources > Metrics at the bottom left.

    image-20221211181249428

  2. If you go to the Containers tab, you can see the deployed containers. You can also see that resources are allocated by 50% as set for the total allocated OCPU and Memory.

    image-20221211181456546

  3. Click the first wordpress container to go to the detail screen. You can check container logs through More actions > View logs in the container menu.

    image-20221211181956093

    image-20221211182248721



As an individual, this article was written with my personal time. There may be errors in the content of the article, and the opinions in the article are personal opinions.

Last updated on 9 Dec 2022