在 MacOS 中使用 multipass 安装 microk8s 环境
在 MacOS 中使用 multipass 安装 microk8s 环境
Multipass & MicroK8s 介绍
What is Kubernetes?
What is Multipass?
What is MicroK8s?
安装 multipass & microk8s
安装 multipass 服务
brew search multipass
brew cask info multipass
brew cask install multipass
multipass version
通过 multipass 安装和启动 microk8s 环境
multipass launch --name microk8s-vm --mem 4G --disk 40G
multipass list
multipass stop microk8s-vm
multipass delete microk8s-vm
multipass purge
在虚机中安装 microk8s 服务
multipass exec microk8s-vm -- sudo snap install microk8s --classic
multipass exec microk8s-vm -- sudo iptables -P FORWARD ACCEPT
查看 microk8s 的 snap 包信息,比如版本信息
multipass exec microk8s-vm -- sudo snap info microk8s
增加账号访问权限,简化操作
# 默认 ubuntu 账号无权限操作集群,均需要 sudo
# 可将 ubuntu 账号加入 microk8s 用户组以便简化访问
multipass exec microk8s-vm -- sudo usermod -a -G microk8s ubuntu
multipass exec microk8s-vm -- sudo sudo chown -f -R ubuntu ~/.kube
增加访问公钥,简化操作
# 在 ~/.ssh/authorized_keys 增加自己的公钥,则可方便的进行SSH登录
multipass shell microk8s-vm
ssh ubuntu@192.168.64.2
查看磁盘空间
multipass exec microk8s-vm -- df -kh
查看 kubeconfig 配置
multipass exec microk8s-vm -- /snap/bin/microk8s.config
在 kubeconfig 中可以找到集群信息,可登录查看
server: https://192.168.64.2:16443
username: admin
password: xxx
增加 DNS 插件,必须安装,多处依赖使用
multipass exec microk8s-vm -- /snap/bin/microk8s.enable dns
multipass exec microk8s-vm -- /snap/bin/microk8s.enable dashboard
尝试访问 Grafana 地址
https://192.168.64.2:16443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
安装 Dashboard UI
multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
使用 Bearer Token 进行鉴权访问
# 为安全考虑,Dashboard UI 需要使用 Bearer Token 进行鉴权访问,使用如下命令获取 Token
multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl -n kube-system get secret | grep default-token | cut -d " " -f1
multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl -n kube-system describe secret default-token-qqt75
访问 Dashboard UI
https://192.168.64.2:16443/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
查看集群组件状态
multipass exec microk8s-vm -- /snap/bin/microk8s.status
可通过指定配置文件进行访问
# 把kubeconfig保存至本地 /Users/xxx/.kube/microk8s-vm.yml,则可通过指定配置文件进行访问
kubectl --insecure-skip-tls-verify --kubeconfig="/Users/xxx/.kube/microk8s-vm.yml" get pods --all-namespaces # 把kubeconfig保存至本地 ~/.kube/config,则可通过指定配置文件进行访问
kubectl --insecure-skip-tls-verify get pods --all-namespaces
安装 registry 组件
# The MicroK8s registry will not be enabled by default, so needs run the following to enable it.
multipass exec microk8s-vm -- /snap/bin/microk8s.enable registry
查看集群内组件状态
multipass exec microk8s-vm -- /snap/bin/microk8s.status | grep enabled
urban-iptable-management # 简单的IP地址查询服务,服务自治,无外部依赖
urban-district-management # 简单的省市区查询服务,服务自治,无外部依赖
urban-traffic-management # 简单的模拟服务间调用,依赖 district 服务查询城市信息
urban-gateway-management # 模拟API网关,将访问转发至其他服务
Github Repo:https://github.com/gaochundong/urbanboot
本地 docker image 构建
cd urbanboot docker build -t urban-iptable-management-app:latest --file ./urban-iptable-management/docker/Dockerfile .
docker build -t urban-district-management-app:latest --file ./urban-district-management/docker/Dockerfile .
docker build -t urban-traffic-management-app:latest --file ./urban-traffic-management/docker/Dockerfile .
docker build -t urban-gateway-management-app:latest --file ./urban-gateway-management/docker/Dockerfile .
删除无用镜像
docker images
docker rmi --force $(docker images | grep "^<none>" | awk '{print $3}')
docker images
保存本地镜像至文件
# Save one or more images to a tar archive
docker save -o urban-iptable-management-app.tar urban-iptable-management-app:latest
docker save -o urban-district-management-app.tar urban-district-management-app:latest
docker save -o urban-traffic-management-app.tar urban-traffic-management-app:latest
docker save -o urban-gateway-management-app.tar urban-gateway-management-app:latest
拷贝镜像文件至 microk8s 机器
scp ./urban-iptable-management-app.tar ubuntu@192.168.64.2:/tmp
scp ./urban-district-management-app.tar ubuntu@192.168.64.2:/tmp
scp ./urban-traffic-management-app.tar ubuntu@192.168.64.2:/tmp
scp ./urban-gateway-management-app.tar ubuntu@192.168.64.2:/tmp
安装镜像至 registry
multipass exec microk8s-vm -- /snap/bin/microk8s.ctr namespaces list
multipass exec microk8s-vm -- /snap/bin/microk8s.ctr images list -q multipass exec microk8s-vm -- /snap/bin/microk8s.ctr images import /tmp/urban-iptable-management-app.tar
multipass exec microk8s-vm -- /snap/bin/microk8s.ctr images import /tmp/urban-district-management-app.tar
multipass exec microk8s-vm -- /snap/bin/microk8s.ctr images import /tmp/urban-traffic-management-app.tar
multipass exec microk8s-vm -- /snap/bin/microk8s.ctr images import /tmp/urban-gateway-management-app.tar multipass exec microk8s-vm -- /snap/bin/microk8s.ctr images list -q | grep urban
删除镜像
multipass exec microk8s-vm -- /snap/bin/microk8s.ctr images remove docker.io/library/urban-iptable-management-app:latest
multipass exec microk8s-vm -- /snap/bin/microk8s.ctr images remove docker.io/library/urban-district-management-app:latest
multipass exec microk8s-vm -- /snap/bin/microk8s.ctr images remove docker.io/library/urban-traffic-management-app:latest
multipass exec microk8s-vm -- /snap/bin/microk8s.ctr images remove docker.io/library/urban-gateway-management-app:latest
在部署文件中配置镜像位置
# 替换deployment.yaml文件中的image路径
/Users/xxx/g/github/urbanboot/urban-district-management/kubernetes/deployment.yaml
创建 Namespace
kubectl --insecure-skip-tls-verify create namespace urbanboot
部署应用
kubectl --insecure-skip-tls-verify apply -f /Users/xxx/g/github/urbanboot/urban-iptable-management/kubernetes/deployment.yaml -n urbanboot
kubectl --insecure-skip-tls-verify apply -f /Users/xxx/g/github/urbanboot/urban-district-management/kubernetes/deployment.yaml -n urbanboot
kubectl --insecure-skip-tls-verify apply -f /Users/xxx/g/github/urbanboot/urban-traffic-management/kubernetes/deployment.yaml -n urbanboot
kubectl --insecure-skip-tls-verify apply -f /Users/xxx/g/github/urbanboot/urban-gateway-management/kubernetes/deployment.yaml -n urbanboot
查看部署
kubectl --insecure-skip-tls-verify get deployments -n urbanboot
kubectl --insecure-skip-tls-verify get pods -n urbanboot
删除部署,会自动删除 Pods
kubectl --insecure-skip-tls-verify delete deployment urban-iptable-management-app -n urbanboot
kubectl --insecure-skip-tls-verify delete deployment urban-district-management-app -n urbanboot
kubectl --insecure-skip-tls-verify delete deployment urban-traffic-management-app -n urbanboot
kubectl --insecure-skip-tls-verify delete deployment urban-gateway-management-app -n urbanboot
创建 Service
kubectl --insecure-skip-tls-verify get services -n urbanboot
multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl expose -h multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl expose deployment urban-iptable-management-app --type=ClusterIP --port=7200 --name=urban-iptable-management-app -n urbanboot
multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl expose deployment urban-iptable-management-app --type=NodePort --port=7200 --name=urban-iptable-management-nodeport -n urbanboot multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl expose deployment urban-district-management-app --type=ClusterIP --port=7200 --name=urban-district-management-app -n urbanboot
multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl expose deployment urban-district-management-app --type=NodePort --port=7200 --name=urban-district-management-nodeport -n urbanboot multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl expose deployment urban-traffic-management-app --type=ClusterIP --port=7200 --name=urban-traffic-management-app -n urbanboot
multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl expose deployment urban-traffic-management-app --type=NodePort --port=7200 --name=urban-traffic-management-nodeport -n urbanboot multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl expose deployment urban-gateway-management-app --type=ClusterIP --port=7200 --name=urban-gateway-management-app -n urbanboot
multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl expose deployment urban-gateway-management-app --type=NodePort --port=7200 --name=urban-gateway-management-nodeport -n urbanboot multipass exec microk8s-vm -- /snap/bin/microk8s.kubectl expose deployment urban-traffic-management-app --type=LoadBalancer --port=7200 --name=urban-traffic-management-loadbalancer -n urbanboot
- 参考:Kubernetes NodePort vs LoadBalancer vs Ingress? When should I use what?
- The big downside is that each service you expose with a LoadBalancer will get its own IP address, and you have to pay for a LoadBalancer per exposed service, which can get expensive!
使用配置文件创建 Service
kubectl --insecure-skip-tls-verify expose -f /Users/xxx/g/github/urbanboot/urban-traffic-management/kubernetes/service.yaml -n urbanboot
kubectl --insecure-skip-tls-verify expose -f /Users/xxx/g/github/urbanboot/urban-traffic-management/kubernetes/nodeport.yaml -n urbanboot
删除 Service
kubectl --insecure-skip-tls-verify delete service urban-iptable-management-app -n urbanboot
kubectl --insecure-skip-tls-verify delete service urban-iptable-management-nodeport -n urbanboot
kubectl --insecure-skip-tls-verify delete service urban-district-management-app -n urbanboot
kubectl --insecure-skip-tls-verify delete service urban-district-management-nodeport -n urbanboot
kubectl --insecure-skip-tls-verify delete service urban-traffic-management-app -n urbanboot
kubectl --insecure-skip-tls-verify delete service urban-traffic-management-nodeport -n urbanboot
kubectl --insecure-skip-tls-verify delete service urban-gateway-management-app -n urbanboot
kubectl --insecure-skip-tls-verify delete service urban-gateway-management-nodeport -n urbanboot
查一下 TCP 端口监听
multipass exec microk8s-vm -- netstat -nl -t
查看部署事件,按照时间排序
kubectl --insecure-skip-tls-verify get events -n urbanboot --sort-by=.metadata.creationTimestamp
查看 Pod 日志
kubectl --insecure-skip-tls-verify get pods -n urbanboot
kubectl --insecure-skip-tls-verify describe pod urban-traffic-management-app-58d7578547-p277h -n urbanboot kubectl --insecure-skip-tls-verify logs urban-traffic-management-app-58d7578547-p277h -n urbanboot
kubectl --insecure-skip-tls-verify logs urban-traffic-management-app-58d7578547-p277h -n urbanboot --tail=20
查看 Endpoint 信息
# Spring Cloud Kubernetes 会通过 API 查询 Endpoints
kubectl --insecure-skip-tls-verify get services -n urbanboot
kubectl --insecure-skip-tls-verify get endpoints -n urbanboot
kubectl --insecure-skip-tls-verify get all --all-namespaces
kubectl --insecure-skip-tls-verify get all -n urbanboot
kubectl --insecure-skip-tls-verify describe services urban-traffic-management-nodeport -n urbanboot
kubectl --insecure-skip-tls-verify describe services urban-traffic-management-app -n urbanboot
访问 NodePort 端口
curl -s http://192.168.64.2:30211
curl -s http://192.168.64.2:30211 -i
curl -s http://192.168.64.2:30211 -v
登录 Pod 环境
kubectl --insecure-skip-tls-verify exec -it urban-traffic-management-app-58d7578547-p277h -n urbanboot -- /bin/bash
查看 Java 进程
java -version
env | grep JAVA
ps -ef|grep java
版权声明:本篇文章《在 MacOS 中使用 multipass 安装 microk8s 环境》由作者 Dennis Gao 发表自博客园个人技术博客,未经作者本人同意禁止以任何的形式转载,任何自动的或人为的爬虫转载行为均为耍流氓。
在 MacOS 中使用 multipass 安装 microk8s 环境的更多相关文章
- 02.01Linux中软件的安装、环境搭建
图1 图2 图3 redis安装 图4 =====================linux下的软件的安装====================安装方式:Yum/rpm/源码安装yum:通过分析rp ...
- Linux中jdk的安装和环境变量的配置
我安装的linux系统版本是RedHat4 64位,jdk版本为jdk-6u10-linux-i586.bin 1.首先找到安装包的位置->进入此文件夹,此bin格式的文件可用./命令直接进行安 ...
- SeetaFace教程(一) 在 VS 中的编译安装和环境配置
SeetaFace开源库由FaceDetection.FaceAlignment.FaceIdentification三部分组成.FaceDetection是在一副图片中检测出人脸区域,以一个方形区域 ...
- macOS 中Boost的安装和使用
1 安装Boost 1.1 使用源码安装 下载Boost源码 解压放在任意目录,例如/home/wang/ ./bootstrap.sh,默认的位置是在usr/local下面;可以通过--prefix ...
- macOS 下 PHPStorm + Xdebug 调试 Docker 环境中的代码
0x00 描述 宿主机是 mac mini,构建的项目在 docker 中,所以需要在 PHPStorm 上配置 Xdebug 进行远程代码调试. 0x01 环境 宿主机:macOS High Sie ...
- macOS Sierra上面的php开发环境安装
本文参考资料: 启动apache时,解决 How to Fix AH00558 and AH00557 httpd apr_sockaddr_info_get() Error Message ...
- CentOS使用yum源中自带的rpm包安装LAMP环境
CentOS使用yum源中自带的rpm包安装LAMP环境.这是Linux下安装LAMP的环境一种最基本最简便的方式.新手可以从容安装使用. 1. 安装基础包(可选安装)yum install -y w ...
- MAC机中安装RUBY环境
在安装CocoaPods之前要先配置好RUBY环境,本文就怎么安装RUBY的环境进行一总结.安装Ruby环境首先需要安装Xcode然后需要安装Homebrew,接下来需要安装RVM最后安装Ruby环境 ...
- macOS中安装docker
如官方文档中所说: 1.点击进入boot2docker/osx-installer release页面. 2.在下载页面中点击 Boot2Docker-x.x.x.pkg 来下载 Boot2Docke ...
随机推荐
- C. Helga Hufflepuff's Cup 树形dp 难
C. Helga Hufflepuff's Cup 这个题目我感觉挺难的,想了好久也写了很久,还是没有写出来. dp[i][j][k] 代表以 i 为根的子树中共选择了 j 个特殊颜色,且当前节点 i ...
- 记jmeter接口测试动态获取验证码
在用jmeter做接口测试时,需要动态的获取验证码,以便在登录成功后可以获取token,但是在测试的过程中,遇到了一个问题,想在这里给大家分享一下: 环境描述 在获取验证码的http请求下加后 ...
- LDheatmap | SNP连锁不平衡图(LD)可视化,自己数据实现版!
本文首发于“生信补给站”,https://mp.weixin.qq.com/s/Gl6BChxSYbSHMo9oMpufPg 连锁不平衡图,用来可视化不同SNP之间的连锁程度,前同事间俗称“倒三角”图 ...
- 向Redis里存入数据
实现思路:1. 从Redis缓存获取URL统计网址清单2. 逐条拼凑SQL统计语句,暂时不能支持批量计算,因为按单个网址统计.3. 发送到HIVE JDBC执行SQL并等待返回结果4 ...
- LeetCode--Array--Container With Most Water (Medium)
11. Container With Most Water (Medium)# Given n non-negative integers a1, a2, ..., an , where each r ...
- CF#633C Spy Syndrome 2 DP+二分+hash
Spy Syndrome 2 题意 现在对某个英文句子,进行加密: 把所有的字母变成小写字母 把所有的单词反过来 去掉单词之间的空格 比如:Kira is childish and he hates ...
- 【csu oj 1542】线段树
题目大意:给定一个合法的括号序列(只包含'(',')'),有q次操作,对每次操作改变一个位置的括号,求最左端的位置,使得改变这个位置上的括号以后,新序列合法(完全配对). 思路:对于合法的括号序列,如 ...
- java ->动态页面技术(JSP)
动态页面技术(JSP/EL/JSTL) JSP技术 jsp脚本和注释 jsp脚本: 1)<%java代码%> ----- 内部的java代码翻译到service方法的内部 2)<%= ...
- 二、YARN
一.YARN 介绍 yarn 是下一代 MapReduce,即 MRv2,是在第一代 MapReduce 基础上演变而来的,主要是为了解决原始 Hadoop 扩展性较差,不支持多计算框架而提出的,通俗 ...
- noi7219 复杂的整数划分问题
noi7219 复杂的整数划分问题 #include <bits/stdc++.h> using namespace std; ; int dp1[maxn][maxn], dp2[max ...