ITSC-docker
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # instruction guide of dockerization and k8s of barnpa on minikube and azure --- ## Step 1 : Update the application tags : __\#optional__ __\#not a part of dockerization__ ### why update the application before dockerization? the original barnpa use codeigniter2 framework and php5. The current version of codeigniter is version 4, which has a lot of difference. The most important thing is that the official codeigniter image on docker hub starts from codeigniter 3, and it is really difficult to download codeigniter 2 from the internet nowadays. Therefore, upgrading the application is a must before dockerization. And we upgrade this to version 4 if we need to upgrade it anyway. Read the website for more information : [codeigniter4 website](https://codeigniter4.github.io/userguide/) ### development environment A normal development environment will be download a codeigniter 4 framework in your localhost and test the application using localhost. In this way, you need to set up a database in localhost as well. A better way will be using docker as development environment. You can use volume mount to sync the files on localhost and inside the container. There is a well-made docker set up for this purpose. https://github.com/atsanna/codeigniter4-docker Following the instruction will create a docker environment with a new codeigniter 4 framework embedded. ### what to do / what to pay attention when upgrade the application Disable the use of phpCAS in the project because phpCAS is not usable in this project. In addition to the changes to function prototypes, the file structure is changed too. So pay attention to the url and file links in the project. Remember to change the `.env` file in the project root to set the environment variable. The `.env` file can be created from duplicate the `env` file and add a dot in the name. Uncomment some lines in the file if specific environment parameter needs to be set. Moreover, remember to change the `ci_sessions` table in the `.sql` file because codeigniter 4 require new table structure in the sql file in order to use session data. For more information, check : [codeigniter4 session](https://codeigniter4.github.io/userguide/libraries/sessions.html#session-drivers) ## Step 2 : create a local image of codeigniter 4 create a file structure : <application folder name>/ - app/ - public/ - mysql/ - barnpa.sql - Dockerfile - .env - yaml/ - kustomization.yaml - codeigniter4.yaml - codeigniter4-mysql.yaml the `app` and `public` folder are the `app` and `public` from the codeigniter4 project. The `.env` file is the environment file for the project which will be used in the docker environment (if you use docker as the development environment which I introduce above, then the `env` file will be very similar in here). The `Dockerfile` is for creating a new image base on the new barnpa in codeigniter4 and the files in yaml folder is for deploying the application in kubernetes. ### How to write the docker file ```Dockerfile FROM atsanna/codeigniter4:latest RUN apt-get update RUN apt-get install RUN apt-get install -y vim RUN ["apt-get", "install", "-y", "libzip-dev"] RUN ["docker-php-ext-install", "mysqli", "pdo", "pdo_mysql", "zip"] RUN touch /usr/local/etc/php/conf.d/uploads.ini \ && echo "upload_max_filesize=64M;\r\n post_max_size=128M;\r\nmemory_limit = 512M" >> /usr/local/etc/php/conf.d/uploads.ini RUN rm -r /codeigniter4/app /codeigniter4/public COPY ./.env /codeigniter4/ COPY ./public /codeigniter4/public COPY ./app /codeigniter4/app ``` This is the content of the `Dockerfile`. The base image will be a pre-made codeigniter4 image which is public on docker hub : [atsanna/codeigniter4 ](https://hub.docker.com/r/atsanna/codeigniter4). However, we add a few utilities on top of the base image for some reasons. First, we add vim to the image such that `vi` command can be used inside the container. We also install `mysqli` and `pdo_mysql` extensions for connection to database and allowing php 7 to use caching_sha2_password in mysql 8 respectively. We also increase the `upload_max_filesize` of the apache web server to 64MB as the default `upload_max_filesize` is 2MB which is too small and will cause error when uploading soundfiles. Finally, we remove the original files in the codeigniter4 framework and add our own files into the container. ### build the docker image locally try to create a local image and test if the web app work perfectly. We can do this by using a `docker-compose.yaml` file to create a container of web server and a container of mysql all at once. ```yaml version: "3.1" services : codeigniter4: container_name: "codeigniter4" build: context: ./ image: codeigniter4 restart: always ports: - 8081:80 links : - codeigniter4-mysql codeigniter4-mysql : container_name: 'codeigniter4-mysql' command: mysqld --default-authentication-plugin=mysql_native_password image : mysql:8.0.20 environment: MYSQL_ROOT_PASSWORD: rootpassword MYSQL_DATABASE: barnpa MYSQL_USER: barnpauser MYSQL_PASSWORD: barnpapassword ports: - 3306:3306 ``` This is the content of `docker-compose.yaml`. Run this file using docker-compose up -d --build the `-d` flag mean run the containers in detached mode and `--build` flag mean rebuild the docker images. __Note that we set the mysql environment and hostname in the `docker-compose` file. Therefore, we need to change the `.env` to match the `docker-compose` file.__ Then you should be able to access the barnpa by `localhost:8081`. Run `docker-compose down` to tear the containers after test. ## Step 3 : deploy the application of azure kubernetes __If you are not familiar with the azure CLI and kubernetes CLI, please read the official documentation or the instruction guide we provided for the dockerization of iLearn.__ First login azure using command az login Then create a resource group using command az group create --name <resoruces group name> --location <location e.g. eastus> Then create a azure container registry (ACR) to hold the image using command az acr create --resource-group <name of resoruce group> --name <name of acr> --sku Basic __Actually, the ACR is just a cloud repos to store your image. It is because when we deploy our application in kubernetes, it needs a place to pull the image. The cloud repository does not have to be on azure.__ Then login the ACR using command az acr login --name <acr name> Then tag the local image and push it to ACR image_name=<image name> acr_login_server=$(az acr show --name barnpaAcr --query loginServer --output tsv) docker tag $image_name $acr_login_server/$image_name docker push $acr_login_server/$image_name check whether the image is push using the command az acr repository list --name <acr name> create a kubernetes cluster with specific number of nodes on azure kubernetes service (AKS) az aks create --resource-group <resource group> --name <cluster name> --node-count <number of node> --enable-addons monitoring --generate-ssh-keys connect the kubectl CLI with the cluster az aks get-credentials --resource-group <resource group> --name <cluster name> if you have more than one cluster, you can use kubectl config view to view the context and cluster that kubectl is connected to. To switch between kubernetes cluster, use kubectl config use-context <context name> to ensure that you create node successfully kubectl get nodes ## Step 4 - prepare .yaml file for kubernetes We create two `.yaml` files, one for the set up of web server and another one for the set up of database in the cluster. These two files can be grouped and run together by a `kustomization.yaml` file. The files are too long and will not be included here. However, the files contains comments which explain some details. ### integrate ACR with kubernetes cluster This official contains comprehensive guide of different methods to connect ACR with kubernetes cluster : https://docs.microsoft.com/en-us/azure/container-registry/container-registry-authentication In the `codeigniter4.yaml`, we specify the image as ```yaml containers: - image: barnpaacr.azurecr.io/codeigniter4:latest imagePullPolicy: IfNotPresent name: codeigniter4 ports: ... ``` By default, kubernetes cannot access the ACR. Therefore you need to authenticate ACR with the AKS. An easier way will be attaching the ACR with AKS such that AKS will know the image in the ACR. This can be done using this command az aks update -n <cluster name> -g <resource group name> --attach-acr <acrName> ### deploy the application Run this command kubectl apply -k ./ the `-k` flag means that kubectl will use the `kustomization.yaml` to do the set up. Check if the resources are created using command kubectl get all

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully