简介
在工作中我们往往需要使用容器的相关环境进行测试与开发,这篇文档主要记录了我这边设置容器相关开发的方法,主要使用minikube,docker,vagrant,virtualbox,vscode,brew等软件
环境
操作系统: macOS Catalina
正文
1.安装Xcode Command Line Tools
xcode-select --install
2.安装Homebrew
# 安装brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# 国内用户可以使用gitee加速
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
# 卸载方法
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"
# 国内用户
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"
3.安装相关软件
brew cask install virtualbox
brew cask install vagrant
brew cask install vagrant-manager
4. 安装minikube
# Homebrew安装
brew install kubernetes-cli
brew cask install minikube
# 二进制安装
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64
sudo install minikube-darwin-amd64 /usr/local/bin/minikube
Ps:
minikube初始化kubernetes集群
minikube start --network-plugin=cni --driver=virtualbox --cni=calico --cpus=4 --memory=8g --image-mirror-country cn --docker-env http_proxy=http://192.168.99.1:8000 --docker-env https_proxy=http://192.168.99.1:8000 --docker-env no_proxy=localhost,127.0.0.1,::1,192.168.99.0/24
5. 安装Golang
brew install go
mkdir -p ~/development/golang/{src,bin,pkg}
# 使用zsh的shell
cat >~/.zshrc<< EOF
#golang
export GOPATH=~/development/golang
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
EOF
6. 安装kubebuilder
# 可以使用Homebrew安装,但是不建议,因为kubebuilder需要依赖etcd,kube-apiserver,kubectl
brew install kubebuilder
wget https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.1/kubebuilder_2.3.1_darwin_amd64.tar.gz
mkdir -p /usr/local/kubebuilder/2.3.1
tar xf kubebuilder_2.3.1_darwin_amd64.tar.gz -C /usr/local/kubebuilder/2.3.1/
cat >~/.zshrc<< EOF
#kubebuilder
export PATH=$PATH:/usr/local/kubebuilder/2.3.1/bin
EOF
7.安装docker
brew install cask docker
或
brew install --cask orbstack
8.安装vscode
brew cask install visual-studio-code
vscode推荐插件:
Beautify
Chinese (Simplified) Language Pack for Visual Studio Code
Code Runner
Comment Translate
Docker
Docker Compose
Docker Explorer
ESLint
Git History
Go
Hugo Language and Syntax Support
Image preview
Insert Date String
Jupyter
Kubernetes
Markdown All in One
Markdown Preview Enhanced
Monokai++
python
Vetur
Remote Development
vscode-icons
vue
YAML
我的vscode的settings.json ~/Library/Application Support/Code/User/settings.json
{
// Editor
// 字体
//"editor.fontFamily": "Menlo, Monaco, 'Courier New', monospace",
"editor.fontFamily": "'Cascadia Code', Consolas, 'Courier New', monospace, '苹方-简', 'Sarasa Gothic SC'",
"editor.fontLigatures": false,
"editor.fontSize": 16,
//"editor.fontWeight": "500",
"editor.tabSize": 4,
//超链接下划线
"editor.links": false,
"window.zoomLevel": 0,
"editor.minimap.enabled": true,
"editor.minimap.maxColumn": 100,
"editor.detectIndentation": false,
"editor.wordWrap": "on",
"editor.renderWhitespace": "none",
"editor.snippetSuggestions": "top",
"editor.suggestSelection": "first",
"editor.renderLineHighlight": "all",
"editor.quickSuggestions": {
"other": true,
"comments": false,
"strings": false
},
// Workbench
"workbench.statusBar.visible": true,
"workbench.activityBar.visible": true,
"workbench.editor.highlightModifiedTabs": true,
"workbench.sideBar.location": "right",
"workbench.startupEditor": "none",
//1.40.0+,自定义 activeBar 颜色
"workbench.colorCustomizations": {
"activityBar.activeBorder": "#f8bf02",
"activityBar.activeBackground": "#2f88b4",
},
"workbench.colorTheme": "Monokai",
"workbench.iconTheme": "vscode-icons",
// Window
"window.titleBarStyle": "custom",
// 面包屑导航
"breadcrumbs.enabled": true,
"explorer.confirmDelete": false,
"explorer.confirmDragAndDrop": false,
"vsicons.dontShowNewVersionMessage": true,
"files.associations": {
"*.vue": "vue",
"*.wxss": "css",
"*.wxml": "html",
"*.ts": "javascript"
},
// Markdown
"[markdown]": {
"editor.wordWrap": "on",
"editor.renderWhitespace": "all",
"editor.quickSuggestions": {
"others": true,
"comments": true,
"strings": true
},
"editor.acceptSuggestionOnEnter": "on"
},
// Markdown All in One
"markdown.extension.toc.updateOnSave": false,
"markdown.extension.toc.levels": "2..3",
// Markdown Preview Enhanced
"markdown-preview-enhanced.mermaidTheme": "default",
"markdown-preview-enhanced.previewTheme": "atom-dark.css",
"markdown-preview-enhanced.codeBlockTheme": "monokai.css",
// Search
"search.showLineNumbers": true,
// Go
"go.goroot": "/usr/local/Cellar/go/1.15.3/libexec",
"go.gopath": "~/development/golang",
// 使用 Go Modules 时无需 inferGopath
"go.inferGopath": false,
"go.useLanguageServer": true,
//自动完成未导入的包
"go.autocompleteUnimportedPackages": true,
"go.gotoSymbol.includeImports": false,
"go.gotoSymbol.includeGoroot": false,
"go.useCodeSnippetsOnFunctionSuggest": true,
"go.useCodeSnippetsOnFunctionSuggestWithoutType": true,
"go.lintOnSave": "file",
"go.buildOnSave": "off",
"go.formatTool": "goreturns",
"go.docsTool": "gogetdoc",
"go.testFlags": [
"-v"
],
"go.languageServerExperimentalFeatures": {
"diagnostics": false,
},
// python
"python.pythonPath": "~/.pyenv/versions/3.8.1/bin/python",
// Terminal
//终端
//"terminal.external.osxExec": "iTerm.app",
//终端shell
"terminal.integrated.shell.osx": "zsh",
//终端字体
"terminal.integrated.fontFamily": "Hack Nerd Font",
// 代理
"http.proxyStrictSSL": false,
"http.proxy": "http://127.0.0.1:8000",
// Git
"git.ignoreLegacyWarning": true,
"git.autofetch": true,
"git.enableSmartCommit": true,
//dart
"[dart]": {
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.rulers": [
80
],
"editor.selectionHighlight": false,
"editor.suggest.snippetsPreventQuickSuggestions": false,
"editor.suggestSelection": "first",
"editor.tabCompletion": "onlySnippets",
"editor.wordBasedSuggestions": false
},
"dart.openDevTools": "flutter",
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"vs-kubernetes": {
"vs-kubernetes.draft-path.mac": "~/.vs-kubernetes/tools/draft/darwin-amd64/draft",
"vs-kubernetes.minikube-path.mac": "~/.vs-kubernetes/tools/minikube/darwin-amd64/minikube",
"vs-kubernetes.helm-path.mac": "~/.vs-kubernetes/tools/helm/darwin-amd64/helm"
},
"C_Cpp.updateChannel": "Insiders",
"code-runner.runInTerminal": true,
// InsertDateString插件时间格式设置
"insertDateString.format": "YYYY-MM-DDThh:mm:ssZZZ",
}