ksonnet 一个简化编写以及部署kubernetes的工具
Posted rongfengliang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ksonnet 一个简化编写以及部署kubernetes的工具相关的知识,希望对你有一定的参考价值。
ksonnet 是一个基于jsonnet的快速简化kubernetes yaml 配置的工具,可以实现配置的复用
同时也包含一个registry 的概念,可以实现可复用组件的分发,同时支持helm
环境准备
- 安装cli
使用mac 系统
brew install ksonnet/tap/ks
- 包含的命令
ks --help
----
Usage:
ks [flags]
ks [command]
Available Commands:
apply Apply local Kubernetes manifests (components) to remote clusters
component Manage ksonnet components
delete Remove component-specified Kubernetes resources from remote clusters
diff Compare manifests, based on environment or location (local or remote)
env Manage ksonnet environments
generate Use the specified prototype to generate a component manifest
help Help about any command
import Import manifest
init Initialize a ksonnet application
module Manage ksonnet modules
param Manage ksonnet parameters for components and environments
pkg Manage packages and dependencies for the current ksonnet application
prototype Instantiate, inspect, and get examples for ksonnet prototypes
registry Manage registries for current project
show Show expanded manifests for a specific environment.
upgrade Upgrade ks configuration
validate Check generated component manifests against the server‘s API
version Print version information for this ksonnet binary
Flags:
--dir string Ksonnet application root to use; Defaults to CWD (default "/Users/dalong")
-h, --help help for ks
--tls-skip-verify Skip verification of TLS server certificates
-v, --verbose count Increase verbosity. May be given multiple times.
Use "ks [command] --help" for more information about a command.
基本使用
- init 应用
ks init dalongdemo
- 生成的项目结构
- 定于部署的组件
以下操作只是演示,我们可以使用命令行工具,快速生成应用的组件
ks generate deployed-service dalongdemo --image dalongrong/appdemo:1.0 --type ClusterIP
如下:
- 查看生成的yaml
从下面的可以看出还是很方便的
ks show default
---
apiVersion: v1
kind: Service
metadata:
labels:
ksonnet.io/component: dalongdemo
name: dalongdemo
spec:
ports:
- port: 80
targetPort: 80
selector:
app: dalongdemo
type: ClusterIP
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
labels:
ksonnet.io/component: dalongdemo
name: dalongdemo
spec:
replicas: 1
selector:
matchLabels:
app: dalongdemo
template:
metadata:
labels:
app: dalongdemo
spec:
containers:
- image: dalongrong/appdemo:1.0
name: dalongdemo
ports:
- containerPort: 80
- helm 的集成
添加仓库
ks registry add helm-stable https://kubernetes-charts.storage.googleapis.com
添加charts
ks pkg install helm-stable/wordpress
效果
说明
ksonnet 基于jsonet 的开发模型让yaml文件的编写可以实现模块,共享,我们可以像写代码一样写
yaml 文件了,同时可以实现复用
参考资料
https://ksonnet.io/docs/examples/helm/
https://ksonnet.io/get-started/
https://github.com/ksonnet/ksonnet
以上是关于ksonnet 一个简化编写以及部署kubernetes的工具的主要内容,如果未能解决你的问题,请参考以下文章