4、Kubernetes 资源清单
资源清单格式
apiVersion: group/apiversion # 如果没有给定 group 名称,那么默认为 core,
可以使用 kubectl api-versions # 获取当前 k8s 版本上所有的 apiVersion 版本信息( 每个版本可能不同 )
kind: #资源类别
metadata: #资源元数据
name
namespace
lables
annotations # 主要目的是方便用户阅读查找
spec: # 期望的状态(disired state)
status:# 当前状态,本字段有 Kubernetes 自身维护,用户不能去定义
资源清单的常用命令
获取 apiversion 版本信息
kubectl api-versions
获取资源的 apiVersion 版本信息
kubectl explain pod
kubect explain ingress
字段配置格式
apiVersion <string> #表示字符串类型
metadata <Object> #表示需要嵌套多层字段
labels <map[string]string> #表示由k:v组成的映射
finalizers <[]string> #表示字串列表
ownerReferences <[]Object> #表示对象列表
hostPID <boolean> #布尔类型
priority <integer> #整型
name <string> -required- #如果类型后面接 -required-,表示为必填字段
通过定义清单文件创建 Pod
定义pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-demo
namespace: default
labels:
app: myapp
version: v1
spec:
containers:
- name: myapp-1
image: wangyanglinux/myapp:v1
- name: busybox-1
image: busybox:latest
command:
- "/bin/sh"
- "-c"
- "sleep 3600"
根据yaml文件进行启动容器
kubectl apply -f pod.yaml
查看容器报错的方法:
查看pod容器的详细信息,包括容器的状态信息等
kubectl describe pod pod-demo
查看容器log日志
kubectl logs pod-demo -c myapp-1
修改service,暴露外网端口
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Service
metadata:
creationTimestamp: "2020-02-22T12:45:10Z"
labels:
run: nginx-linux
name: nginx-linux
namespace: default
resourceVersion: "166951"
selfLink: /api/v1/namespaces/default/services/nginx-linux
uid: e85b8894-c0f2-4c9f-81cd-1361505ccb21
spec:
clusterIP: 10.110.158.235
externalTrafficPolicy: Cluster
ports:
- nodePort: 30357
port: 30000
protocol: TCP
targetPort: 80
selector:
run: nginx-linux
sessionAffinity: None
type: NodePort
status:
loadBalancer: {}
还没有评论,来说两句吧...