当前位置:网站首页>说了半天跨平台,今儿咱就来跨跨!(完结篇)——Kubenetes上手实践
说了半天跨平台,今儿咱就来跨跨!(完结篇)——Kubenetes上手实践
2022-08-09 17:18:00 【InfoQ】
两句闲言
几片碎语
准备工作
故事该从哪里说起呢?
先试着搭个开发环境吧
基本情况
准备工作
启用wsl2
# 在powershell或者命令提示符终端中输入该命令即可
wsl.exe –set-default-version 2
wsl -l -v
安装合适的Ubuntu发行版
# 更新可用软件包的存储库和列表
sudo apt update
# 根据安装的软件包更新系统 > “-y” 将自动批准更改
sudo apt upgrade -y
安装Docker Desktop
启动wsl集成
sudo apt upgrade -y
*一点额外操作
"registry-mirrors": [
"https://{系统分配的前缀}.mirror.aliyuncs.com"
]
创建集群
kind还是minikube?
- 安装,这个没什么可说的,在wsl中安装minikube还是很流畅的,执行着几段命令就可以
# 下载
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
# 使二进制可执行文件
chmod +x ./minikube
# 将二进制文件移动到可执行路径
sudo mv ./minikube /usr/local/bin/
- 启动
minikube start
用kind来创建一个集群
安装kind
# 下载
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.14.0/kind-linux-amd64
# 使二进制可执行文件
chmod +x ./kind
# 将二进制文件移动到可执行路径
sudo mv ./kind /usr/local/bin/kind
创建一个单节点集群
# 创建一个单节点集群,名字叫wslkind
kind create cluster --name wslkind
利用Docker Desktop 创建集群(推荐)
开启kubernetes
打包应用镜像
编写k8s启动文件
apiVersion: apps/v1
kind: Deployment
metadata:
name: k8s-cipapi
namespace: default
labels:
name: k8s-cipapi
spec:
replicas: 1
selector:
matchLabels:
name: k8s-cipapi
template:
metadata:
labels:
name: k8s-cipapi
spec:
containers:
- name: k8s-cipapi
image: tonydf/cipapi:v220804 # 镜像标识,如果本地不存在就会到dockerhub拉取,当然这个拉去规则是可以设置的。
ports:
- containerPort: 8002
---
apiVersion: v1
kind: Service
metadata:
name: k8s-cipapi
namespace: default
spec:
type: NodePort
selector:
name: k8s-cipapi
ports:
- port: 8002
targetPort: 80
- apiVersion,创建该对象所使用的 Kubernetes API 的版本
- kind,想要创建的对象的类别
- metadata,帮助唯一标识对象的一些数据,包括一个 name 字符串、UID 和可选的 namespace
- spec,你所期望的该对象的状态
- ---,这三个线表示同级别内容的分割
启动集群
kubectl apply -f .\cipapi.yaml
kubectl get deployments
kubectl get services
数据验证
kubectl get svc
通过kubernetes-dashboard来检测集群状态
安装
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.6.0/aio/deploy/recommended.yaml
访问
# 要从本地工作站访问 Dashboard,必须为 Kubernetes 集群创建一个代理访问通道
kubectl proxy
创建rbac配置文件
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard
kubectl apply -f dashboard-adminuser.yaml
kubectl -n kubernetes-dashboard create token admin-user
结束语
边栏推荐
猜你喜欢
ref的使用
[SUCTF 2019]CheckIn
Volatile:JVM 我警告你,我的人你别乱动
动手学深度学习_风格迁移
[极客大挑战 2019]HardSQL
How to choose a good SaaS knowledge base tool?
The most complete architect knowledge map in history
What are some good open source automation testing frameworks to recommend?
An in-depth understanding of the implementation principle of Hybrid
2022 全球 AI 模型周报
随机推荐
What are some good open source automation testing frameworks to recommend?
openEuler Xiong Wei: How do you view the SIG organization model in the open source community?
C#介绍及基本数据类型
论文解读:Deep-4MCW2V:基于序列的预测指标,以鉴定大肠杆菌中的N4-甲基环胞嘧啶位点
自学软件测试,学到什么程度可以出去找工作啊?
手写flexible.js的原理实现,我终于明白移动端多端适配
我不写单元测试,被批了
approach和method的区别
Metasploit——辅助模块(Auxiliary)
Discuz! Forum program installation + template configuration tutorial
URLError: <urlopen error [Errno 11004] getaddrinfo failed>调用seaborn-data无法使用
jmeter-录制脚本
API接口是什么?API接口常见的安全问题与安全措施有哪些?
JMeter notes 6 | JMeter recording agent (configuration)
[Pycharm easy to use function]
win10 uwp 改变鼠标
win10 uwp 无法附加到CoreCLR
Entry node of ring in leetcode/linked list
以技术御风险,护航云原生 | 同创永益 X 博云举办产品联合发布会
毕昇编译器优化:Lazy Code Motion