Skip to content

Instantly share code, notes, and snippets.

View kkbruce's full-sized avatar
🆚
Coding for fun

Bruce Chen kkbruce

🆚
Coding for fun
View GitHub Profile
@kkbruce
kkbruce / Set-K8sWndowsNodeFirewallRules.ps1
Created August 11, 2023 09:30
Set Windows Firewall for Windows Node for Kubernetes
# Reference: https://kubernetes.io/docs/reference/networking/ports-and-protocols/
# Control plane Firewall rules
New-NetFirewallRule -DisplayName "Kubernetes API server" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 6443
New-NetFirewallRule -DisplayName "etcd server client API" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 2379-2380
New-NetFirewallRule -DisplayName "Kubelet API" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 10250
New-NetFirewallRule -DisplayName "kube-scheduler" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 10259
New-NetFirewallRule -DisplayName "kube-controller-manager" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 10257
# Worker node Firewall rules
@kkbruce
kkbruce / SetupK8sEnv.sh
Last active August 13, 2024 16:03
Kubernetes Cluster安裝前執行環境準備。(僅在Ubuntu 22.04測試過)
#!/bin/bash
echo "[Step 1] Disable and turn off SWAP"
# https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#before-you-begin
# 文件最後一行:Swap disabled. You **MUST** disable swap in order for the kubelet to work properly.
# K8s需要關閉swap
# 先手動關閉
swapoff -a
# 將fstab裡的swap那一行註解
sed -i '/swap/s/^/#/' /etc/fstab
@kkbruce
kkbruce / Setup-UltimatePowerShell.txt
Last active February 3, 2023 06:08
設定PowerShell Core與WSL好看又實用的指令碼環境
# 新主機
winget install Microsoft.WindowsTerminal
winget install Microsoft.PowerShell
# 安裝 oh-my-posh
# https://ohmyposh.dev/docs/migrating,不要再使用 install-Module 來安裝
# Install-Module oh-my-posh -Scope CurrentUser -Force
winget install JanDeDobbeleer.OhMyPosh
# 安裝 Terminal-Icons 模組
Install-Module -Name Terminal-Icons -Repository PSGallery -Force
# 安裝最新版 PSReadLine 模組
@kkbruce
kkbruce / Save-OfflineWindowsTerminal.ps1
Last active December 26, 2023 12:09
Auto save and setup offline Windows Terminal app
# reference: https://blog.darkthread.net/blog/install-winterminal-wo-internet/
Write-Host "Confirm https://github.com/microsoft/terminal/releases get latest version download Url"
Write-Host "Running PowerShell Core runtime"
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
Invoke-WebRequest https://github.com/microsoft/terminal/releases/download/v1.12.10393.0/Microsoft.WindowsTerminal_1.12.10393.0_8wekyb3d8bbwe.msixbundle -OutFile Microsoft.WindowsTerminal.msixbundle
Rename-Item .\Microsoft.WindowsTerminal.msixbundle .\Microsoft.WindowsTerminal.zip
Expand-Archive .\Microsoft.WindowsTerminal.zip .\WTSource\.
# PowerShell not support .msix extract.
Expand-Archive .\WTSource\CascadiaPackage_1.12.10393.0_x64.msix .\WindowsTerminal\.
@kkbruce
kkbruce / Get-AzureBlobFile.ps1
Created August 27, 2021 08:03
Download Azure Blob file by Azure PowerShell
#!pwsh
Import-Module Az.Accounts
Import-Module Az.Storage
Connect-AzAccount
$resourceGroup = "RG"
$storageAccountName = "AN"
$containerName = "CN"
# step 1, clean dangling image
docker rmi $(docker images -f "dangling=true" -q)
# step 2, search "before | since" images
## see "CREATED"
docker images --filter "since=baseimage"
# step 3, get IMAGE ID
docker images --filter "since=baseimage" -q
# step 3-1, Range
docker images --filter "since=baseimage" --filter "before=baseimage"
# step 4, delete "before | since" images
@kkbruce
kkbruce / Install-WebServer.ps1
Created February 17, 2021 08:41
Setup IIS Web Server By Server Core
Install-WindowsFeature -Name Web-Server
Install-WindowsFeature -Name Web-Http-Redirect, Web-Request-Monitor, Web-Http-Tracing, Web-Dyn-Compression, Web-Basic-Auth, Web-Windows-Auth, Web-Net-Ext45, Web-AppInit, Web-Asp-Net45, Web-WebSockets
Install-WindowsFeature -Name Web-Mgmt-Tools -IncludeAllSubFeature
cd \
.\Windows\System32\inetsrv\InetMgr.exe
@kkbruce
kkbruce / FindAWSIPAddress.url
Created May 21, 2020 01:22
Find AWS IP Address Information
https://aws.amazon.com/tw/premiumsupport/knowledge-center/s3-find-ip-address-ranges/
https://docs.aws.amazon.com/general/latest/gr/aws-ip-ranges.html#aws-ip-download
https://docs.aws.amazon.com/powershell/latest/reference/items/Get-AWSPublicIpAddressRange.html
@kkbruce
kkbruce / Send-FTPSFiles.ps1
Created May 19, 2020 08:10
Provide PowerShell upload .zip file to FTPS script
param (
[string]$sourceDir
)
$ftpaddr = "example.com/upload/"
# option
$assemblies = (
"System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL",
"System.IO, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL",
@kkbruce
kkbruce / nlog.config
Created April 7, 2020 03:16
nlog.config Example
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Info"
internalLogFile="c:\temp\internal-nlog.txt">
<!-- 啟用 ASP.NET Core 排版呈現器 -->
<extensions>
<add assembly="NLog.Web.AspNetCore"/>