<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Reene</title>
    <description>The latest articles on DEV Community by Reene (@reene44444).</description>
    <link>https://dev.to/reene44444</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1761616%2Fe7eb642d-0003-460a-b0fa-8daccecdf3cb.png</url>
      <title>DEV Community: Reene</title>
      <link>https://dev.to/reene44444</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/reene44444"/>
    <language>en</language>
    <item>
      <title>[k8s]After restarting the virtual machine, the kube-apiserver of k8s cannot start normally</title>
      <dc:creator>Reene</dc:creator>
      <pubDate>Tue, 03 Dec 2024 22:07:11 +0000</pubDate>
      <link>https://dev.to/reene44444/k8safter-restarting-the-virtual-machine-the-kube-apiserver-of-k8s-cannot-start-normally-14n9</link>
      <guid>https://dev.to/reene44444/k8safter-restarting-the-virtual-machine-the-kube-apiserver-of-k8s-cannot-start-normally-14n9</guid>
      <description>&lt;p&gt;After restarting the device:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

kubectl get node
The connection to the server x.x.x.x:6443 was refused - did you specify the right host or port?
systemctl status kube-apiserver prompts:

Unit kube-apiserver.service could not be found
There is no such service, so it is judged that the configuration file is wrong
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Decided to reconstruct the K8S cluster&lt;/p&gt;

&lt;p&gt;Solution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# 1. Check if kubectl command is working&lt;/span&gt;
kubectl get node

&lt;span class="c"&gt;# 2. Go to the home directory&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; ~

&lt;span class="c"&gt;# 3. Check if the .kube directory exists&lt;/span&gt;
ll &lt;span class="nt"&gt;-a&lt;/span&gt;  &lt;span class="c"&gt;# List all files to check if .kube directory exists&lt;/span&gt;

&lt;span class="c"&gt;# 4. Remove the .kube directory&lt;/span&gt;
&lt;span class="nb"&gt;sudo rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; .kube/

&lt;span class="c"&gt;# 5. Restart Docker service&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart docker  &lt;span class="c"&gt;# Restart Docker&lt;/span&gt;

&lt;span class="c"&gt;# 6. Restart kubelet service&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart kubelet  &lt;span class="c"&gt;# Restart kubelet&lt;/span&gt;

&lt;span class="c"&gt;# 7. Reset the Kubernetes setup&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;kubeadm reset  &lt;span class="c"&gt;# Reset Kubernetes cluster&lt;/span&gt;

&lt;span class="c"&gt;# 8. Remove CNI configurations&lt;/span&gt;
&lt;span class="nb"&gt;sudo rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; /etc/cni/  &lt;span class="c"&gt;# Delete CNI configurations&lt;/span&gt;

&lt;span class="c"&gt;# 9. Reinitialize Kubernetes with specific settings&lt;/span&gt;
kubeadm init &lt;span class="nt"&gt;--kubernetes-version&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1.23.5 &lt;span class="nt"&gt;--apiserver-advertise-address&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;192.168.1.21 &lt;span class="nt"&gt;--image-repository&lt;/span&gt; registry.aliyuncs.com/google_containers &lt;span class="nt"&gt;--service-cidr&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;192.1.0.0/16 &lt;span class="nt"&gt;--pod-network-cidr&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;192.244.0.0/16

&lt;span class="c"&gt;# 10. After successful initialization, configure Kubernetes for the user&lt;/span&gt;
&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt;/.kube  &lt;span class="c"&gt;# Create the .kube directory&lt;/span&gt;
&lt;span class="nb"&gt;sudo cp&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; /etc/kubernetes/admin.conf &lt;span class="nv"&gt;$HOME&lt;/span&gt;/.kube/config  &lt;span class="c"&gt;# Copy admin config&lt;/span&gt;
&lt;span class="nb"&gt;sudo chown&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;:&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt;/.kube/config  &lt;span class="c"&gt;# Change ownership of the config file&lt;/span&gt;

&lt;span class="c"&gt;# 11. Download the Flannel network configuration file&lt;/span&gt;
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml  &lt;span class="c"&gt;# Download Flannel YAML file&lt;/span&gt;

&lt;span class="c"&gt;# 12. Copy the kube-flannel.yml file to /opt and apply it&lt;/span&gt;
&lt;span class="nb"&gt;sudo cp &lt;/span&gt;kube-flannel.yml /opt/  &lt;span class="c"&gt;# Copy the Flannel YAML file to /opt directory&lt;/span&gt;
kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; /opt/kube-flannel.yml  &lt;span class="c"&gt;# Apply the Flannel configuration&lt;/span&gt;

&lt;span class="c"&gt;# After these steps, check the node status&lt;/span&gt;
kubectl get nodes  &lt;span class="c"&gt;# Check if the node is ready&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Issue with Flannel and CoreDNS Pods Not Starting:
When checking the pods, Flannel and CoreDNS are not starting.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

Error: Flannel is having an issue where it cannot obtain the necessary subnet lease. Specifically, the PodCIDR &lt;span class="o"&gt;(&lt;/span&gt;assigned IP range &lt;span class="k"&gt;for &lt;/span&gt;pods&lt;span class="o"&gt;)&lt;/span&gt; 192.244.0.0/24 is not included within Flannel’s network configuration subnet 10.244.0.0/16.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Fixing the Subnet Configuration:
Edit the Flannel ConfigMap: To resolve the subnet issue, the Flannel ConfigMap needs to be updated.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;First, inspect the Flannel Pod:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
kubectl describe pod kube-flannel-ds-99grr &lt;span class="nt"&gt;-n&lt;/span&gt; kube-flannel  &lt;span class="c"&gt;# Describe the Flannel pod for detailed information&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check the logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
kubectl logs kube-flannel-ds-fqvvv &lt;span class="nt"&gt;-n&lt;/span&gt; kube-flannel  &lt;span class="c"&gt;# Check the Flannel pod logs for errors&lt;/span&gt;
Error Explanation: The Flannel network plugin is unable to get a subnet lease because the PodCIDR 192.244.0.0/24 is not within the subnet 10.244.0.0/16 specified &lt;span class="k"&gt;in &lt;/span&gt;Flannel’s configuration.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Solution: You can resolve this by modifying the Flannel network configuration:&lt;/p&gt;

&lt;p&gt;Edit the Flannel ConfigMap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl edit configmap kube-flannel-cfg &lt;span class="nt"&gt;-n&lt;/span&gt; kube-flannel  &lt;span class="c"&gt;# Edit the Flannel ConfigMap in the kube-flannel namespace&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change the subnet in the ConfigMap to match the required PodCIDR.&lt;/p&gt;

&lt;p&gt;After modifying the subnet in the kube-flannel-cfg ConfigMap, Flannel should be able to allocate the necessary subnets and the pods should start successfully.&lt;/p&gt;

</description>
      <category>k8s</category>
    </item>
    <item>
      <title>[Github actions][actions]Core File Organization and Guidelines</title>
      <dc:creator>Reene</dc:creator>
      <pubDate>Sun, 01 Dec 2024 21:42:43 +0000</pubDate>
      <link>https://dev.to/reene44444/github-actionsactions-2pdk</link>
      <guid>https://dev.to/reene44444/github-actionsactions-2pdk</guid>
      <description>&lt;h1&gt;
  
  
  &lt;strong&gt;Custom GitHub Actions: Core File Organization and Guidelines&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Custom GitHub Actions enable users to define specific workflows tailored to their needs. Below are the core conventions and best practices for organizing custom GitHub Actions.&lt;/p&gt;




&lt;h2&gt;
  
  
  0. Installed images in github acitons environment
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md" rel="noopener noreferrer"&gt;https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;1. Folder Organization&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Each custom Action must reside in its own folder, typically under &lt;code&gt;.github/actions&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.github/
  actions/
    action-name/          # Custom Action folder
      action.yml          # Core configuration file (required)
      script.sh           # Optional: Supporting script file
      Dockerfile          # Optional: Docker configuration file
      index.js            # Optional: Entry point for JavaScript Actions
      README.md           # Optional: Action documentation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;2. Core File: &lt;code&gt;action.yml&lt;/code&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;action.yml&lt;/code&gt; is the required configuration file that defines the Action's behavior.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Required Fields&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;name&lt;/code&gt;&lt;/strong&gt;: The Action's name (for identification).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;description&lt;/code&gt;&lt;/strong&gt;: A short description of the Action's purpose.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;inputs&lt;/code&gt;&lt;/strong&gt;: (Optional) Parameters to pass to the Action.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;outputs&lt;/code&gt;&lt;/strong&gt;: (Optional) Values returned by the Action.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;runs&lt;/code&gt;&lt;/strong&gt;: Specifies how the Action should execute.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;3. Types of Actions&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;(1) Composite Actions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A series of steps defined directly in the &lt;code&gt;action.yml&lt;/code&gt; file.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example: &lt;code&gt;action.yml&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;My Composite Action&lt;/span&gt;
&lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;A composite Action example&lt;/span&gt;
&lt;span class="na"&gt;inputs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;example_input&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;An&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;example&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;input"&lt;/span&gt;
    &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;runs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;using&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;composite"&lt;/span&gt;
  &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Print input&lt;/span&gt;
      &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo "Input is ${{ inputs.example_input }}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;(2) JavaScript/TypeScript Actions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Runs on Node.js, allowing complex logic and dependencies.&lt;/p&gt;

&lt;h4&gt;
  
  
  File Structure:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.github/actions/my-js-action/
  action.yml
  index.js            # Main script file
  package.json        # Node.js dependencies
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example: &lt;code&gt;action.yml&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;My JavaScript Action&lt;/span&gt;
&lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;A JavaScript Action example&lt;/span&gt;
&lt;span class="na"&gt;inputs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;example_input&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;An&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;example&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;input"&lt;/span&gt;
    &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;runs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;using&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;node16"&lt;/span&gt;
  &lt;span class="na"&gt;main&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;index.js&lt;/span&gt;       &lt;span class="c1"&gt;# Entry point&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;(3) Docker Actions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Runs inside a Docker container with a custom environment.&lt;/p&gt;

&lt;h4&gt;
  
  
  File Structure:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.github/actions/my-docker-action/
  action.yml
  Dockerfile          # Required for Docker Actions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example: &lt;code&gt;action.yml&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;My Docker Action&lt;/span&gt;
&lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;A Docker Action example&lt;/span&gt;
&lt;span class="na"&gt;inputs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;example_input&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;An&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;example&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;input"&lt;/span&gt;
    &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;runs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;using&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;docker"&lt;/span&gt;
  &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Dockerfile"&lt;/span&gt;
  &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;${{ inputs.example_input }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example: &lt;code&gt;Dockerfile&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; ubuntu:20.04&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;apt-get update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; curl jq
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; entrypoint.sh /entrypoint.sh&lt;/span&gt;
&lt;span class="k"&gt;ENTRYPOINT&lt;/span&gt;&lt;span class="s"&gt; ["/entrypoint.sh"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;4. Optional Files&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;README.md&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Provides documentation for the Action, including:

&lt;ul&gt;
&lt;li&gt;Description of functionality.&lt;/li&gt;
&lt;li&gt;List of input and output parameters.&lt;/li&gt;
&lt;li&gt;Examples of usage.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Scripts&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Include additional shell or Python scripts as needed to support the Action's logic.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;5. Referencing Custom Actions&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;(1) Local Repository&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If the Action is in the same repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Use Custom Action&lt;/span&gt;
  &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./github/actions/action-name&lt;/span&gt;
  &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;example_input&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;World"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;(2) External Repository&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If the Action is hosted in another public repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Use Custom Action&lt;/span&gt;
  &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;username/repository-name/path/to/action-name@v1&lt;/span&gt;
  &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;example_input&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;World"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;6. Best Practices&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;File Naming&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The configuration file must be named &lt;code&gt;action.yml&lt;/code&gt; or &lt;code&gt;action.yaml&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For Docker Actions, a &lt;code&gt;Dockerfile&lt;/code&gt; is required.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For JavaScript Actions, declare all dependencies in &lt;code&gt;package.json&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For Docker Actions, include all required tools in the &lt;code&gt;Dockerfile&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Checkout Repository&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always include &lt;code&gt;actions/checkout&lt;/code&gt; before referencing local Actions to load the repository's content.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;7. Example Workflow Using a Custom Action&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Workflow File: &lt;code&gt;.github/workflows/main.yml&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Example Workflow&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;example&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Checkout Code&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v3&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Use Custom Action&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./github/actions/action-name&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;example_input&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;World"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>githubactions</category>
    </item>
    <item>
      <title>[Subnet][ZeroTier]build local network</title>
      <dc:creator>Reene</dc:creator>
      <pubDate>Fri, 29 Nov 2024 09:09:51 +0000</pubDate>
      <link>https://dev.to/reene44444/vpnbuild-local-network-12ab</link>
      <guid>https://dev.to/reene44444/vpnbuild-local-network-12ab</guid>
      <description>&lt;h1&gt;
  
  
  Configure ZeroTier for Host machine and Ubuntu  Machine
&lt;/h1&gt;

&lt;p&gt;configure ZeroTier for communication between host and an Ubuntu machine.&lt;/p&gt;

&lt;h4&gt;
  
  
  Reference:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;zeroTier center: &lt;a href="https://my.zerotier.com/" rel="noopener noreferrer"&gt;https://my.zerotier.com/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  1. Install ZeroTier
&lt;/h1&gt;

&lt;h2&gt;
  
  
  S Host
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Download the ZeroTier client from &lt;a href="https://www.zerotier.com/download/" rel="noopener noreferrer"&gt;https://www.zerotier.com/download/&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Install and run the application.&lt;/li&gt;
&lt;li&gt;Open the ZeroTier menu bar app and log in to ZeroTier Central.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Ubuntu Virtual Machine
&lt;/h2&gt;

&lt;p&gt;Run the following commands to install ZeroTier:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-s&lt;/span&gt; https://install.zerotier.com | &lt;span class="nb"&gt;sudo &lt;/span&gt;bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  2. Configure ZeroTier Network
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Create a Network
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;a href="https://my.zerotier.com/" rel="noopener noreferrer"&gt;https://my.zerotier.com/&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Log in and click "Create a Network".&lt;/li&gt;
&lt;li&gt;Note the &lt;strong&gt;Network ID&lt;/strong&gt; (e.g., &lt;code&gt;8056c2e21c000001&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Click on the new network and configure:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Name&lt;/strong&gt;: Set a friendly name like &lt;code&gt;HomeNetwork&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Access Control&lt;/strong&gt;: Select &lt;code&gt;Private&lt;/code&gt; to manually approve devices.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  3. Join the ZeroTier Network
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Host
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;In the ZeroTier app, click "Join Network".&lt;/li&gt;
&lt;li&gt;Enter the &lt;strong&gt;Network ID&lt;/strong&gt; and join.&lt;/li&gt;
&lt;li&gt;Approve the device in ZeroTier Central by checking the &lt;code&gt;Auth&lt;/code&gt; box.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Ubuntu  Machine
&lt;/h2&gt;

&lt;p&gt;Run the following command to join the network:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;zerotier-cli &lt;span class="nb"&gt;join&lt;/span&gt; &amp;lt;network-id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check connection status:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;zerotier-cli listnetworks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  4. Assign and Verify IP Addresses
&lt;/h1&gt;

&lt;p&gt;ZeroTier assigns virtual IPs automatically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Host
&lt;/h2&gt;

&lt;p&gt;Find the IP in the ZeroTier menu bar app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ubuntu Machine
&lt;/h2&gt;

&lt;p&gt;Run the following command to check the assigned IP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ip addr show zt&lt;span class="k"&gt;*&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  5. Test Connectivity
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Ping Test
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;From host to Ubuntu:
ping &lt;/li&gt;
&lt;li&gt;From Ubuntu to host:
ping &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  SSH Connection
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;From host:
ssh user@&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  6. Enable ZeroTier on Startup
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Ubuntu Machine
&lt;/h2&gt;

&lt;p&gt;Enable and start the ZeroTier service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;zerotier-one
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl start zerotier-one
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>[CI/CD][Github actions] common template</title>
      <dc:creator>Reene</dc:creator>
      <pubDate>Fri, 29 Nov 2024 06:23:32 +0000</pubDate>
      <link>https://dev.to/reene44444/cicdgit-actions-common-template-29gg</link>
      <guid>https://dev.to/reene44444/cicdgit-actions-common-template-29gg</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This GitHub Actions template is designed to automate the CI/CD pipeline for a backend project. It has two main stages: Build and Deploy. &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Hint:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Replacement instructions:Add the Secrets information provided above (such as DOCKER_USERNAME, NGROK_HOST, etc.) to GitHub's Secrets configuration one by one.&lt;/li&gt;
&lt;li&gt;When using, there is no need to modify ${{ secrets.XXXX }} in the YAML file, GitHub will automatically replace them with the corresponding Secrets values.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Applicable scenarios:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Applicable to Docker image building and pushing.&lt;/li&gt;
&lt;li&gt;Supports deploying projects to specified servers and executing Kubernetes configuration through Ngrok.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: CI/CD for Backend

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          distribution: 'temurin'
          java-version: '17'

      - name: Build with Maven
        run: mvn clean package -DskipTests

      - name: Build Docker image
        run: docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest .

      - name: Push Docker image to DockerHub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      - run: docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest

  deploy:
    runs-on: ubuntu-latest
    needs: build

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      # Load NGROK_PORT and NGROK_HOST from the config file
      - name: Load NGROK configuration
        run: |
          NGROK_PORT=$(yq '.NGROK_PORT' ./.github/workflows/config.yml)
          NGROK_HOST=$(yq '.NGROK_HOST' ./.github/workflows/config.yml)
          echo "NGROK_PORT=$NGROK_PORT" &amp;gt;&amp;gt; $GITHUB_ENV
          echo "NGROK_HOST=$NGROK_HOST" &amp;gt;&amp;gt; $GITHUB_ENV

      # Ensure the target directory exists
      - name: Prepare target directory
        run: |
          sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no -p ${{ env.NGROK_PORT }} ${{ secrets.SSH_USER }}@${{ env.NGROK_HOST }} &amp;lt;&amp;lt; 'EOF'
          mkdir -p /home/linlin1/io-multiple-backend/
          EOF

      # Transfer code to the target server
      - name: Transfer code to server
        run: |
          sshpass -p "${{ secrets.SSH_PASSWORD }}" scp -o StrictHostKeyChecking=no -P ${{ env.NGROK_PORT }} -r * ${{ secrets.SSH_USER }}@${{ env.NGROK_HOST }}:/home/linlin1/io-multiple-backend/

      # Deploy Kubernetes configurations
      - name: Deploy on server
        run: |
          sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no -p ${{ env.NGROK_PORT }} ${{ secrets.SSH_USER }}@${{ env.NGROK_HOST }} &amp;lt;&amp;lt; 'EOF'
          cd /home/linlin1/io-multiple-backend/k8s
          kubectl apply -f .
          EOF


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Placeholder&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example Value&lt;/th&gt;
&lt;th&gt;Secret Key in GitHub&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;${{ secrets.DOCKER_USERNAME }}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;DockerHub username&lt;/td&gt;
&lt;td&gt;your-docker-username&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DOCKER_USERNAME&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;${{ secrets.DOCKER_PASSWORD }}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;DockerHub password&lt;/td&gt;
&lt;td&gt;your-docker-password&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DOCKER_PASSWORD&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;${{ secrets.DOCKER_REPO }}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;DockerHub repository name&lt;/td&gt;
&lt;td&gt;dockerRepo&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DOCKER_REPO&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;${{ secrets.SSH_USER }}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;SSH username for the target server&lt;/td&gt;
&lt;td&gt;ubuntu&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SSH_USER&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;${{ secrets.SSH_PASSWORD }}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;SSH password for the target server&lt;/td&gt;
&lt;td&gt;12345678&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SSH_PASSWORD&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  configure config.yml for dynamic ip of ngork
&lt;/h4&gt;

&lt;p&gt;if you choose dynamic ip configuration in ngork, then it is better to configure ngork host and port in config.yml file instead of github secrets.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create config.yml under the same directory:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NGROK_PORT: 12345
NGROK_HOST: 0.tcp.eu.ngrok.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7ohvmxvl1oja652gx91o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7ohvmxvl1oja652gx91o.png" alt="Image description" width="642" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>githubactions</category>
      <category>cicd</category>
    </item>
    <item>
      <title>[Intranet penetration][Ngrok]Expose local services to achieve front-end and back-end debugging</title>
      <dc:creator>Reene</dc:creator>
      <pubDate>Fri, 29 Nov 2024 03:24:28 +0000</pubDate>
      <link>https://dev.to/reene44444/vpcbuild-a-virtual-local-area-network-2p5n</link>
      <guid>https://dev.to/reene44444/vpcbuild-a-virtual-local-area-network-2p5n</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;Achieve front-end and back-end debugging when outside the local network. Besides a)building vpn in aws [aws vpn],b)reverse ssh tunnel, there introduce another method which is more simple to expose local service, to make private cloud have access to local service.&lt;/p&gt;

&lt;h2&gt;
  
  
  0.Using Ngrok (intranet penetration tool)
&lt;/h2&gt;

&lt;p&gt;Ngrok is a lightweight intranet penetration tool that can quickly expose local services to the public network. It is very suitable for scenarios where the host does not have a public IP.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Configure Ngrok in your mechine
&lt;/h2&gt;

&lt;h4&gt;
  
  
  1). Check the system architecture
&lt;/h4&gt;

&lt;p&gt;Run the following command in the terminal to confirm  system architecture:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;uname -m
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;x86_64: 64-bit architecture. &lt;/li&gt;
&lt;li&gt;arm or aarch64: ARM architecture&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2).Download the correct Ngrok binary
&lt;/h4&gt;

&lt;p&gt;x86_64:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ARM64：&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-arm64.tgz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3). Unzip the file
&lt;/h4&gt;

&lt;p&gt;Unzip the file you just downloaded:&lt;/p&gt;

&lt;p&gt;There I use the ubuntu(aarch64)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;tar&lt;/span&gt; &lt;span class="nt"&gt;-xvzf&lt;/span&gt; ngrok-v3-stable-linux-arm64.tgz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the unzip is complete, you should see a file called ngrok.&lt;/p&gt;

&lt;h4&gt;
  
  
  4). Install Ngrok
&lt;/h4&gt;

&lt;p&gt;Move the unzipped file to your system's global path, such as /usr/local/bin:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo mv &lt;/span&gt;ngrok /usr/local/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5). Verify the installation
&lt;/h4&gt;

&lt;p&gt;Check that the installation was successful:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ngrok version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If successful, it will display output similar to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ngrok version 3.x.x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Get an authtoken
&lt;/h2&gt;

&lt;p&gt;Register an Ngrok account and get an authtoken : &lt;a href="https://dashboard.ngrok.com/" rel="noopener noreferrer"&gt;https://dashboard.ngrok.com/&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;go to the setting, and configure payment method, and then choose free tier.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After finish setting, go to token. &lt;br&gt;
Authenticate the ngrok agent. only have to do this once. The Authtoken is saved in the default configuration file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ngrok config add-authtoken &amp;lt;your-token&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Run Ngrok again
&lt;/h2&gt;

&lt;p&gt;Now we can use Ngrok normally. For example, to start an SSH tunnel (port 22):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ngrok tcp 22
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If successful, Ngrok will output an address similar to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Forwarding tcp://0.tcp.ngrok.io:12345 -&amp;gt; localhost:22
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Edit ssh_config
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vim /etc/ssh/sshd_config

PermitRootLogin yes
PasswordAuthentication yes
KbdInteractiveAuthentication yes
UsePAM yes
#PubkeyAuthentication yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdizltltupay0nbidrsm4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdizltltupay0nbidrsm4.png" alt="Image description" width="800" height="314"&gt;&lt;/a&gt;&lt;br&gt;
now we can access our SSH service from the outside using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh user@0.tcp.ngrok.io &lt;span class="nt"&gt;-p&lt;/span&gt; 12345
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;user: Replace with your host's SSH username (e.g. ubuntu).&lt;/li&gt;
&lt;li&gt;tcp.eu.ngrok.io and 12345: from the address and port provided by Ngrok.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4.Configuring Ngrok to Auto-Start on Ubuntu Virtual Machine
&lt;/h2&gt;

&lt;p&gt;This guide explains how to configure Ngrok to start automatically on boot with persistent settings on an Ubuntu virtual machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="c"&gt;# Step 1: Create an Ngrok Configuration File&lt;/span&gt;
&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt;/.ngrok2
nano &lt;span class="nv"&gt;$HOME&lt;/span&gt;/.ngrok2/ngrok.yml

&lt;span class="c"&gt;# Add the following content to ngrok.yml:&lt;/span&gt;
 version: &lt;span class="s2"&gt;"2"&lt;/span&gt;
 authtoken: your-authtoken
 tunnels:
   ssh:
     proto: tcp
     addr: 22

&lt;span class="c"&gt;# Or use:&lt;/span&gt;
&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt;/.ngrok2 &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt; &amp;gt; &lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="sh"&gt;/.ngrok2/ngrok.yml
version: "2"
authtoken: your-authtoken
tunnels:
  ssh:
    proto: tcp
    addr: 22
&lt;/span&gt;&lt;span class="no"&gt;EOF

&lt;/span&gt;&lt;span class="c"&gt;# Save the file and test the configuration&lt;/span&gt;
ngrok start &lt;span class="nt"&gt;--config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;/.ngrok2/ngrok.yml &lt;span class="nt"&gt;--all&lt;/span&gt;

&lt;span class="c"&gt;# Step 2: Create a Systemd Service File&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/systemd/system/ngrok.service

&lt;span class="c"&gt;# Add the following content to the service file:&lt;/span&gt;
 &lt;span class="o"&gt;[&lt;/span&gt;Unit]
 &lt;span class="nv"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Ngrok Service
 &lt;span class="nv"&gt;After&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;network.target

 &lt;span class="o"&gt;[&lt;/span&gt;Service]
 &lt;span class="nv"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/local/bin/ngrok start &lt;span class="nt"&gt;--config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/home/&amp;lt;username&amp;gt;/.ngrok2/ngrok.yml &lt;span class="nt"&gt;--all&lt;/span&gt;
 &lt;span class="nv"&gt;Restart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;on-failure
 &lt;span class="nv"&gt;User&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;username&amp;gt;
 &lt;span class="nv"&gt;WorkingDirectory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/home/&amp;lt;username&amp;gt;
 &lt;span class="nv"&gt;Environment&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"PATH=/usr/local/bin:/usr/bin:/bin"&lt;/span&gt;

 &lt;span class="o"&gt;[&lt;/span&gt;Install]
 &lt;span class="nv"&gt;WantedBy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;multi-user.target

&lt;span class="c"&gt;# Save and exit the file&lt;/span&gt;

&lt;span class="c"&gt;# Step 3: Enable and Start the Service&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl daemon-reload
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl stop ngrok
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl start ngrok
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl status ngrok

&lt;span class="c"&gt;# Enable the service to start on boot&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;ngrok

&lt;span class="c"&gt;# Step 4: Verify Ngrok Auto-Start on Boot&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;reboot

&lt;span class="c"&gt;# After rebooting, check the Ngrok service status&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl status ngrok

&lt;span class="c"&gt;# Confirm Ngrok is running and its tunnels are active&lt;/span&gt;
&lt;span class="c"&gt;# Ngrok’s web interface is available by default at http://127.0.0.1:4040&lt;/span&gt;





&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;go to dashboard:&lt;a href="https://dashboard.ngrok.com/agents" rel="noopener noreferrer"&gt;https://dashboard.ngrok.com/agents&lt;/a&gt;&lt;/p&gt;

</description>
      <category>network</category>
      <category>networking</category>
      <category>intranet</category>
    </item>
    <item>
      <title>[K8s][Commands]</title>
      <dc:creator>Reene</dc:creator>
      <pubDate>Sat, 23 Nov 2024 00:48:10 +0000</pubDate>
      <link>https://dev.to/reene44444/kube-cc6</link>
      <guid>https://dev.to/reene44444/kube-cc6</guid>
      <description>&lt;h2&gt;
  
  
  k8s
&lt;/h2&gt;

&lt;p&gt;use following commands to simulate kubernate clusters&lt;/p&gt;

&lt;h3&gt;
  
  
  0. configure static ip address
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ip route | &lt;span class="nb"&gt;grep &lt;/span&gt;default

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the Netplan configuration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/netplan/01-netcfg.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configure static IP: Add the following to the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;network:
  version: 2
  ethernets:
    ens33: &lt;span class="c"&gt;#Replace with your network card name&lt;/span&gt;
      addresses:
        - 192.168.1.10/24 &lt;span class="c"&gt;# Set a fixed IP address&lt;/span&gt;
      routes:
        - to: default
          via: 192.168.1.1 &lt;span class="c"&gt;#Set the gateway address&lt;/span&gt;
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;netplan apply

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1. ssh
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;openssh-server &lt;span class="nt"&gt;-y&lt;/span&gt;

&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;ssh
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl start ssh

&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl status ssh

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;vim /etc/fstab

&lt;span class="c"&gt;#/swapfile none swap sw 0 0&lt;/span&gt;

&lt;span class="nb"&gt;sudo &lt;/span&gt;reboot
free &lt;span class="nt"&gt;-h&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Master
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Disable Swap (if not disabled)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;swapoff &lt;span class="nt"&gt;-a&lt;/span&gt;
&lt;span class="nb"&gt;sudo sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="s1"&gt;'/swap/d'&lt;/span&gt; /etc/fstab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Import the GPG public key of the Alibaba Cloud image&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;curl -fsSL https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/kubernetes-archive-keyring.gpg&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt-get update&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check /etc/apt/sources.list.d/kubernetes.list configuration
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo rm&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; /etc/apt/sources.list.d/kubernetes.list
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main"&lt;/span&gt; | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /etc/apt/sources.list.d/kubernetes.list

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Update and install Kubernetes
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; kubelet kubeadm kubectl

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Confirm whether the installation is successful
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubelet &lt;span class="nt"&gt;--version&lt;/span&gt;
kubeadm version
kubectl version &lt;span class="nt"&gt;--client&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Install docker before start k8s
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; docker.io
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl start docker
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Initialize the Kubernetes cluster. Run the following command to initialize the Kubernetes master node:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;kubeadm init &lt;span class="nt"&gt;--pod-network-cidr&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;192.168.0.0/16 &lt;span class="nt"&gt;--ignore-preflight-errors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Port-6443,Port-10259,Port-10257,Port-10250



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Set up kubectl to access the cluster
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt;/.kube
&lt;span class="nb"&gt;sudo cp&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; /etc/kubernetes/admin.conf &lt;span class="nv"&gt;$HOME&lt;/span&gt;/.kube/config
&lt;span class="nb"&gt;sudo chown&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;:&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt;/.kube/config
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"export KUBECONFIG=&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/.kube/config"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.bashrc
&lt;span class="nb"&gt;source&lt;/span&gt; ~/.bashrc

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test whether the connection is successful:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl get nodes

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
bash&lt;br&gt;
If the master node status is displayed as Ready, it means that the initialization is successful.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install network plugin (using Flannel)
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Add a working node&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After the master node is initialized, copy the generated command to worker node by using the following command in the master node to join the worker node to the cluster:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;kubeadm token create &lt;span class="nt"&gt;--print-join-command&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If need to deploy an application,  can use kubectl apply or Helm deployment.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. worker
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo apt-get update &amp;amp;&amp;amp; sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common


curl -fsSL https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/kubernetes-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list


sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl


sudo apt-get install -y docker.io


sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl enable kubelet

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;on worker:&lt;br&gt;
&lt;code&gt;mkdir -p $HOME/.kube&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;go to the master:&lt;br&gt;
&lt;code&gt;sudo scp /etc/kubernetes/admin.conf &amp;lt;worker-username&amp;gt;@&amp;lt;worker-node-ip-address&amp;gt;:/home/&amp;lt;worker-username&amp;gt;/.kube/config&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;back to the worker:&lt;br&gt;
&lt;code&gt;sudo chown $(id -u):$(id -g) $HOME/.kube/config&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
check the status:&lt;br&gt;
&lt;code&gt;kubectl get nodes&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>[WebGL2.0][Basic]scene graph</title>
      <dc:creator>Reene</dc:creator>
      <pubDate>Mon, 04 Nov 2024 23:15:28 +0000</pubDate>
      <link>https://dev.to/reene44444/webgl20basicscene-graph-4gmm</link>
      <guid>https://dev.to/reene44444/webgl20basicscene-graph-4gmm</guid>
      <description>&lt;h2&gt;
  
  
  Transition Matrix: localMatrix and worldMatrix
&lt;/h2&gt;

&lt;p&gt;In 3D graphics rendering, both &lt;code&gt;localMatrix&lt;/code&gt; and &lt;code&gt;worldMatrix&lt;/code&gt; are transformation matrices used to describe the position, rotation, and scaling of an object in different spaces. Multiplying these matrices is necessary to progressively apply the transformations of each object in the hierarchy to the overall scene’s world coordinate system. Here’s a deeper explanation of why these matrices are multiplied and their specific roles.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;code&gt;localMatrix&lt;/code&gt; and &lt;code&gt;worldMatrix&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;localMatrix&lt;/code&gt;&lt;/strong&gt;: Represents the transformation of the current node (object) in its local coordinate space. This space is relative to its parent node, meaning the object’s position, rotation, and scaling are all described relative to its parent. Any child nodes will inherit this transformation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;localMatrix describe itself information rather than a single coordinate system, same as worldMatrix.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;worldMatrix&lt;/code&gt;&lt;/strong&gt;: Represents the transformation of the current node in the world (or scene) coordinate space. This matrix transforms the node from its local coordinate space all the way up to the root node of the scene graph, effectively placing it in world space.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Why Multiply the Matrices?
&lt;/h3&gt;

&lt;p&gt;Matrix multiplication is used to apply transformations from one space to another. For instance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The parent node’s &lt;code&gt;worldMatrix&lt;/code&gt;&lt;/strong&gt; represents its position and orientation in the world space.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The current node’s &lt;code&gt;localMatrix&lt;/code&gt;&lt;/strong&gt; represents its position and orientation relative to the parent node.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To compute the position and orientation of the current node in world space, we multiply the parent node’s &lt;code&gt;worldMatrix&lt;/code&gt; by the current node’s &lt;code&gt;localMatrix&lt;/code&gt;. This multiplication effectively applies the parent’s transformation, followed by the current node’s transformation, resulting in the current node’s &lt;code&gt;worldMatrix&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Example: Earth and Moon
&lt;/h3&gt;

&lt;p&gt;Consider a scenario where the Earth orbits the Sun, and the Moon orbits the Earth. Using matrices, we can represent these transformations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Earth’s &lt;code&gt;worldMatrix&lt;/code&gt;&lt;/strong&gt; describes its position and rotation around the Sun in the world (solar system) space.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Moon’s &lt;code&gt;localMatrix&lt;/code&gt;&lt;/strong&gt; describes its position and rotation around the Earth, in Earth’s local space.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To compute the Moon’s position in the world space, we multiply Earth’s &lt;code&gt;worldMatrix&lt;/code&gt; by Moon’s &lt;code&gt;localMatrix&lt;/code&gt;, resulting in Moon’s &lt;code&gt;worldMatrix&lt;/code&gt;. This way, the Moon orbits Earth, which in turn orbits the Sun, capturing the hierarchical transformation relationship.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Conclusion
&lt;/h3&gt;

&lt;p&gt;By multiplying matrices, we can apply each level’s transformation within a hierarchy (like a scene graph), obtaining the final position and orientation of each node in world coordinates. This method is fundamental in 3D scenes, especially for complex parent-child transformation relationships.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>[WebGL2.0][Basic]skinned model</title>
      <dc:creator>Reene</dc:creator>
      <pubDate>Sun, 03 Nov 2024 23:56:16 +0000</pubDate>
      <link>https://dev.to/reene44444/webgl20basicskined-model-41oi</link>
      <guid>https://dev.to/reene44444/webgl20basicskined-model-41oi</guid>
      <description>&lt;h2&gt;
  
  
  1. Relative defination
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Mesh
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Definition of Triangle Count:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The number of triangles in a mesh is determined by the complexity of the object you want to represent. For example:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Simple Shapes&lt;/strong&gt;: A simple cube only requires 12 triangles (6 faces, with each face consisting of 2 triangles).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Complex Shapes&lt;/strong&gt;: A detailed character model may require thousands or even millions of triangles, allowing for finer details such as facial features and clothing folds.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Primitive
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Triangle&lt;/strong&gt;: This is the most basic primitive. Each triangle is defined by 3 vertices (positions) and associated attributes (like color, normals, etc.). During rendering, each triangle can be drawn individually.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Line Segment&lt;/strong&gt;: This is another type of primitive. A line segment consists of 2 vertices and is commonly used to draw edges or connect points. For instance, line segments can represent the edges of a mesh.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Point&lt;/strong&gt;: Points are also a primitive type, representing a single position. They are typically used to represent particles in a particle system or the position of lights.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;Suppose we are creating a 3D cube mesh:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mesh Definition&lt;/strong&gt;: This cube can be made up of 12 triangles. Each face has two triangles, together forming the shape of a cube.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Primitive Usage&lt;/strong&gt;: When rendering this cube, we will utilize multiple primitives (triangles), each containing information about 3 vertices, along with their colors, normals, and other data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This combination of meshes and primitives allows for the construction and rendering of complex objects in a 3D environment efficiently. If you have more questions or need further clarification, feel free to ask!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>[React.js][Webpack] webpack setup for react from scratch</title>
      <dc:creator>Reene</dc:creator>
      <pubDate>Sun, 03 Nov 2024 23:24:31 +0000</pubDate>
      <link>https://dev.to/reene44444/reactjswebpack-webpack-setup-for-react-from-strach-3hel</link>
      <guid>https://dev.to/reene44444/reactjswebpack-webpack-setup-for-react-from-strach-3hel</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=WDpxqopXd9U" rel="noopener noreferrer"&gt;youtube&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/codebubb/react-webpack" rel="noopener noreferrer"&gt;repository&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; @babel/core@^7.12.13 @babel/preset-env@^7.12.13 @babel/preset-react@^7.12.13 babel-loader@^8.2.2 css-loader@^5.0.1 file-loader@^6.2.0 mini-css-extract-plugin@^1.3.5 sass@^1.32.6 sass-loader@^10.1.1 style-loader@^2.0.0 webpack@^5.20.1 webpack-cli@^4.5.0 webpack-dev-server@^3.11.2

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;.barbelrc&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "presets": ["@babel/preset-env", "@babel/preset-react"]
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;webpack.config&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="n"&gt;const&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; = &lt;span class="n"&gt;require&lt;/span&gt;(&lt;span class="s1"&gt;'path'&lt;/span&gt;);
&lt;span class="n"&gt;const&lt;/span&gt; &lt;span class="n"&gt;MiniCssExtractPlugin&lt;/span&gt; = &lt;span class="n"&gt;require&lt;/span&gt;(&lt;span class="s1"&gt;'mini-css-extract-plugin'&lt;/span&gt;);

&lt;span class="n"&gt;module&lt;/span&gt;.&lt;span class="n"&gt;exports&lt;/span&gt; = {
    &lt;span class="n"&gt;output&lt;/span&gt;: {
        &lt;span class="n"&gt;path&lt;/span&gt;: &lt;span class="n"&gt;path&lt;/span&gt;.&lt;span class="n"&gt;join&lt;/span&gt;(&lt;span class="err"&gt;__&lt;/span&gt;&lt;span class="n"&gt;dirname&lt;/span&gt;, &lt;span class="s1"&gt;'/dist'&lt;/span&gt;),
        &lt;span class="n"&gt;filename&lt;/span&gt;: &lt;span class="s1"&gt;'index.bundle.js'&lt;/span&gt;,
    },
    &lt;span class="n"&gt;devServer&lt;/span&gt;: {
        &lt;span class="n"&gt;port&lt;/span&gt;: &lt;span class="m"&gt;3010&lt;/span&gt;,
        &lt;span class="n"&gt;watchContentBase&lt;/span&gt;: &lt;span class="n"&gt;true&lt;/span&gt;,
    },
    &lt;span class="n"&gt;module&lt;/span&gt;: {
        &lt;span class="n"&gt;rules&lt;/span&gt;: [
            {
                &lt;span class="n"&gt;test&lt;/span&gt;: /\.(&lt;span class="n"&gt;js&lt;/span&gt;|&lt;span class="n"&gt;jsx&lt;/span&gt;)$/,
                &lt;span class="n"&gt;exclude&lt;/span&gt;: /&lt;span class="n"&gt;node_modules&lt;/span&gt;/,
                &lt;span class="n"&gt;use&lt;/span&gt;: {
                    &lt;span class="n"&gt;loader&lt;/span&gt;: &lt;span class="s1"&gt;'babel-loader'&lt;/span&gt;
                }
            },
            {
                &lt;span class="n"&gt;test&lt;/span&gt;: /\.&lt;span class="n"&gt;scss&lt;/span&gt;$/,
                &lt;span class="n"&gt;use&lt;/span&gt;: [
                    &lt;span class="n"&gt;MiniCssExtractPlugin&lt;/span&gt;.&lt;span class="n"&gt;loader&lt;/span&gt;,
                    &lt;span class="s1"&gt;'css-loader'&lt;/span&gt;,
                    &lt;span class="s1"&gt;'sass-loader'&lt;/span&gt;,
                ],
            }
        ]
    },
    &lt;span class="n"&gt;plugins&lt;/span&gt;: [&lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;MiniCssExtractPlugin&lt;/span&gt;()],
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;index.html&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;React App&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"main.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"index.bundle.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;index.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;file-loader?name=[name].[ext]!./index.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App.scss&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;appElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;appElement&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webpack</category>
      <category>react</category>
    </item>
    <item>
      <title>[WebGL2.0] [Basic] non-skinned model</title>
      <dc:creator>Reene</dc:creator>
      <pubDate>Sun, 03 Nov 2024 18:53:42 +0000</pubDate>
      <link>https://dev.to/reene44444/webgl20-basic-non-skinned-model-afc</link>
      <guid>https://dev.to/reene44444/webgl20-basic-non-skinned-model-afc</guid>
      <description>&lt;h2&gt;
  
  
  1. &lt;strong&gt;gl_Position = projection * view * model * position;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;    &lt;span&gt;&lt;/span&gt;    &lt;strong&gt;from local/model position to the position of final clip space&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Three Transformation Maxtrix:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Projection&lt;/strong&gt;: Projection Transformation Matrix&lt;/p&gt;

&lt;p&gt;transform &lt;u&gt;view coordinate system&lt;/u&gt; to &lt;u&gt;clip space coodinate system&lt;/u&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;View&lt;/strong&gt;: View Transformation Matrix&lt;/p&gt;

&lt;p&gt;transform &lt;u&gt;model coordinate system&lt;/u&gt; to &lt;u&gt;view coordinnate system&lt;/u&gt;(move the position of camera)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Model&lt;/strong&gt;: Model Transformation Matrix&lt;/p&gt;

&lt;p&gt;transform &lt;u&gt;local coordinate&lt;/u&gt; into &lt;u&gt;model coordinate system/game world coordinate system(absolute coordinate)&lt;/u&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Postition&lt;/strong&gt;: The local coordinates of the vertices&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;local coordinate system(relative coordinate system)&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Note:&lt;/li&gt;
&lt;li&gt;&lt;p&gt;the origin of coordinate system of position and model is defined by developer based on requirment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;the coordinate system of world and model cooresponding to model and postion matrix data respectly:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

            Absolute(World) Y+ axis
                 Y (0, 1, 0)
               |
               |                           Local(Model) Y+ axis
               |                             |  /
               |                             | /
               |                             |
               |                  ---------- o (1, 0, 1)  ← Local(Model) Origin ---- Local X+ axis
               |                           / |  
               |                          /  |
               |                         /   |
               |                        /    |
               |                       /     | 
               |______________________/______|__________ X (1, 0, 0)  Absolute(World) X+ axis
              /                     Local(Model) Z+ axis
             /
            /
           /
          Z (0, 0, 1)
   Absolute(World) Z+ axis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. WebGL uses Column primary order in default where as C++ uses Row primary order in default.
&lt;/h2&gt;

&lt;p&gt;In WebGL, matrices are stored in &lt;strong&gt;column-major order&lt;/strong&gt;, which affects matrix arrangement and calculation order. This storage method influences how matrices are defined and used in WebGL. Here are some common practices when working with column-major matrices in WebGL:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Matrix Definition and Arrangement&lt;/strong&gt;
## Matrix Definition and Arrangement
With column-major storage, the columns of the matrix are stored sequentially. For example, a 4x4 matrix &lt;strong&gt;M&lt;/strong&gt; in column-major order looks like this:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;M = | m11 m21 m31 m41 | | m12 m22 m32 m42 | | m13 m23 m33 m43 | | m14 m24 m34 m44 |&lt;/p&gt;

&lt;p&gt;In WebGL, this matrix is represented as a one-dimensional array in column-major order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;matrix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
     &lt;span class="nx"&gt;m11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m21&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m31&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m41&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;// First column&lt;/span&gt;
     &lt;span class="nx"&gt;m12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;// Second column&lt;/span&gt;
     &lt;span class="nx"&gt;m13&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m33&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m43&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;// Third column&lt;/span&gt;
     &lt;span class="nx"&gt;m14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m34&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m44&lt;/span&gt;   &lt;span class="c1"&gt;// Fourth column&lt;/span&gt;
   &lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Consistent Matrix and Array Format&lt;/strong&gt;
When passing matrix data to WebGL shaders, it’s essential to use a consistent format. For instance, when passing a 4x4 transformation matrix, WebGL’s &lt;code&gt;uniformMatrix4fv&lt;/code&gt; function expects the array in column-major order:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="nx"&gt;gl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uniformMatrix4fv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;matrix&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;false&lt;/code&gt; indicates that the matrix should not be transposed. Since WebGL uses column-major order by default, ensure that the data format matches this requirement, as JavaScript’s standard &lt;code&gt;Math&lt;/code&gt; library may use row-major order by default.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Matrix Multiplication Order&lt;/strong&gt;
In practice, column-major order affects the multiplication sequence of matrices. In this system, matrices are multiplied &lt;strong&gt;from right to left&lt;/strong&gt;, meaning the last transformation is applied first. For example:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The resulting matrix &lt;strong&gt;M&lt;/strong&gt; can be expressed as the product of transformation matrices &lt;strong&gt;T&lt;/strong&gt;, &lt;strong&gt;R&lt;/strong&gt;, and &lt;strong&gt;S&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;M&lt;/strong&gt; = &lt;strong&gt;T&lt;/strong&gt; ⋅ &lt;strong&gt;R&lt;/strong&gt; ⋅ &lt;strong&gt;S&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this equation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;S&lt;/strong&gt; is a scaling matrix,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;R&lt;/strong&gt; is a rotation matrix,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;T&lt;/strong&gt; is a translation matrix.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In column-major order, this sequence first applies scaling, then rotation, and finally translation.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Using Utility Libraries&lt;/strong&gt;
Using libraries like &lt;code&gt;glMatrix&lt;/code&gt; simplifies matrix operations in WebGL. These libraries generally follow column-major order, aligning with WebGL’s requirements and avoiding the need for manual matrix format adjustments. For example:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;let modelMatrix = mat4.create();// create a Identity matrix&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;modelMatrix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mat4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="c1"&gt;// create a Identity matrix&lt;/span&gt;
&lt;span class="c1"&gt;//M = T ⋅ R ⋅ S the principle of mutiply of matrix is from right to left &amp;lt;----- caused by colum major order&lt;/span&gt;
   &lt;span class="nx"&gt;mat4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;modelMatrix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;modelMatrix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// Translation&lt;/span&gt;
   &lt;span class="nx"&gt;mat4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;modelMatrix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;modelMatrix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;angle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// Rotation&lt;/span&gt;
   &lt;span class="nx"&gt;mat4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;modelMatrix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;modelMatrix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;sx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sz&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// Scaling&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Debugging and Conversion&lt;/strong&gt;
Understanding column-major storage helps when debugging matrix calculations. If a matrix result is unexpected, check that the data arrangement in shaders matches column-major order.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webgl</category>
      <category>javascript</category>
    </item>
    <item>
      <title>[Event-Driven] understanding</title>
      <dc:creator>Reene</dc:creator>
      <pubDate>Fri, 11 Oct 2024 08:49:58 +0000</pubDate>
      <link>https://dev.to/reene44444/event-driven-understanding-234o</link>
      <guid>https://dev.to/reene44444/event-driven-understanding-234o</guid>
      <description>&lt;p&gt;From the learning, the event-driven is mainly like passive meaning, using message queue to drive other services to do other things.&lt;/p&gt;

</description>
      <category>eventdriven</category>
      <category>pubsub</category>
    </item>
  </channel>
</rss>
