我正在按照指南將資料庫連接到 kubernetes: https ://itnext.io/basic-postgres-database-in-kubernetes-23c7834d91ef
在 Windows 10 64 位上安裝 Kubernetes (minikube) 后: https ://minikube.sigs.k8s.io/docs/start/
我在資料庫嘗試連接和存盤密碼時遇到“base64”問題。由于 PowerShell 無法識別它。我想知道是否有人知道如何解決這個問題并仍然使用 Windows 或其他方法來讓我繼續閱讀指南的其余部分?
錯誤代碼:
base64 : The term 'base64' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:131
... postgresql -o jsonpath="{.data.postgresql-password}" | base64 --decod ...
~~~~~~
CategoryInfo : ObjectNotFound: (base64:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
export : The term 'export' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
export POSTGRES_PASSWORD=$(kubectl get secret --namespace default pos ...
~~~~~~
CategoryInfo : ObjectNotFound: (export:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
Windows Powershell 錯誤訊息
uj5u.com熱心網友回復:
在 Mac OS 和一些 *nix 發行版中找到的base64cli 在 Windows 上不可用。
您可以撰寫一個名為base64模仿base64unix 工具行為的小函式:
function base64 {
# enumerate all pipeline input
$input |ForEach-Object {
if($MyInvocation.UnboundArguments -contains '--decode'){
# caller supplied `--decode`, so decode
$bytes = [convert]::FromBase64String($_)
[System.Text.Encoding]::ASCII.GetString($bytes)
} else {
# default mode, encode ascii text as base64
$bytes = [System.Text.Encoding]::ASCII.GetBytes($_)
[convert]::ToBase64String($bytes)
}
}
}
這應該可以替代 ASCII/UTF7 文本和 base64 之間的轉換:
PS ~> 'Hello, World!' |base64 --encode
SGVsbG8sIFdvcmxkIQ==
PS ~> 'Hello, World!' |base64 --encode |base64 --decode
Hello, World!
要與現有腳本一起使用,請在執行其他腳本之前,在 shell 中使用函式定義簡單地點源腳本:
PS ~> . .\path\to\base64.ps1
以上內容也適用于腳本。如果你有一個多行粘貼感知 shell(Windows 的默認控制臺主機和 PSReadLine 應該沒問題),你也可以直接將函式定義粘貼到提示符中:)
uj5u.com熱心網友回復:
您正在嘗試在 Windows 上執行為類 Unix平臺撰寫的命令列,包括:
- 他們期望的外部效用
base64( ) - 他們使用的shell 語法
export POSTGRES_PASSWORD=$(...)( ; 為 POSIX 兼容的 shell 撰寫,例如bash)。
Mathias 的有用答案向您展示了如何base64在 PowerShell 中模擬實用程式,您甚至可以export通過額外的、非平凡的努力來模擬 shell 命令,但并非所有情況都可以這樣處理,例如\"用于轉義的命令列"字符(這將破壞 PowerShell 的語法,請嘗試echo "3\" of snow.")。
因此,如果可行,我建議通過WSL按原樣運行命令,或者花時間將命令列轉換為PowerShell-native 等效項。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/411853.html
標籤:
上一篇:裝有iOS15的設備在測驗應用內購買時會忽略我的沙盒帳戶
下一篇:Css改變兩個標題之間的間距
