1,JSON格式用于接口之間消息的傳遞
2,YAML格式用于配置和管理
3,YAML是一種簡潔的非標(biāo)記性語言
成都創(chuàng)新互聯(lián)公司是專業(yè)的紅塔網(wǎng)站建設(shè)公司,紅塔接單;提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作,網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行紅塔網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
縮進(jìn)標(biāo)識(shí)層級(jí)關(guān)系
不支持制表符(tab)縮進(jìn),使用空格縮進(jìn)
通常開頭縮進(jìn)兩個(gè)空格
字符后縮進(jìn)一個(gè)空格,如冒號(hào),逗號(hào)等
“---”表示YAML格式,一個(gè)文件的開始
“#”表示注釋
`查看應(yīng)用名稱`
[root@master1 ~]# kubectl api-versions
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
apps/v1
apps/v1beta1
apps/v1beta2
authentication.k8s.io/v1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1
authorization.k8s.io/v1beta1
autoscaling/v1
autoscaling/v2beta1
autoscaling/v2beta2
batch/v1
batch/v1beta1
certificates.k8s.io/v1beta1
coordination.k8s.io/v1beta1
events.k8s.io/v1beta1
extensions/v1beta1
networking.k8s.io/v1
policy/v1beta1
rbac.authorization.k8s.io/v1
rbac.authorization.k8s.io/v1beta1
scheduling.k8s.io/v1beta1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1
[root@master1 ~]# mkdir demo
[root@master1 ~]# cd demo/
[root@master1 demo]# vim nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.15.4
ports:
- containerPort: 80
#插入內(nèi)容后按Esc退出插入模式,輸入:wq保存退出
[root@master1 demo]# kubectl create -f my-nginx.yaml
deployment.apps/my-nginx created
[root@master1 demo]# kubectl get pods
NAME READY STATUS RESTARTS AGE
`my-nginx-d55b94fd-kc2gl 1/1 Running 0 47s`
`my-nginx-d55b94fd-tkr42 1/1 Running 0 47s`
nginx-6c94d899fd-8pf48 1/1 Running 0 23h
nginx-deployment-5477945587-f5dsm 1/1 Running 0 22h
nginx-deployment-5477945587-hmgd2 1/1 Running 0 22h
nginx-deployment-5477945587-pl2hn 1/1 Running 0 22h
[root@master1 demo]# vim my-nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
name: my-nginx-service
labels:
app: nginx
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
selector:
app: nginx
#插入內(nèi)容后按Esc退出插入模式,輸入:wq保存退出
[root@master1 demo]# kubectl create -f my-nginx-service.yaml
service/my-nginx-service created
`查看服務(wù)`
[root@master1 demo]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.0.0.1 443/TCP 8d
`my-nginx-service NodePort 10.0.0.210 80:40377/TCP 20s`
nginx-service NodePort 10.0.0.242 80:40422/TCP 33h
[root@master1 demo]# kubectl run my-nginx --image=nginx --port=80 --replicas=2 --dry-run
kubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed in a future version. Use kubectl create instead.
deployment.apps/my-nginx created (dry run)
[root@master1 demo]# kubectl run my-nginx --image=nginx --port=80 --replicas=2 --dry-run -o yaml
kubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed in a future version. Use kubectl create instead.
apiVersion: apps/v1beta1
kind: Deployment
metadata:
creationTimestamp: null
labels:
run: my-nginx
name: my-nginx
spec:
replicas: 2
selector:
matchLabels:
run: my-nginx
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
run: my-nginx
spec:
containers:
- image: nginx
name: my-nginx
ports:
- containerPort: 80
resources: {}
status: {}
[root@master1 demo]# kubectl run my-nginx --image=nginx --port=80 --replicas=2 --dry-run -o yaml > nginx-deploy.yaml
kubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed in a future version. Use kubectl create instead.
[root@master1 demo]# kubectl run my-nginx --image=nginx --port=80 --replicas=2 --dry-run -o json
kubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed in a future version. Use kubectl create instead.
{
"kind": "Deployment",
"apiVersion": "apps/v1beta1",
"metadata": {
"name": "my-nginx",
"creationTimestamp": null,
"labels": {
"run": "my-nginx"
}
},
"spec": {
"replicas": 2,
"selector": {
"matchLabels": {
"run": "my-nginx"
}
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"run": "my-nginx"
}
},
"spec": {
"containers": [
{
"name": "my-nginx",
"image": "nginx",
"ports": [
{
"containerPort": 80
}
],
"resources": {}
}
]
}
},
"strategy": {}
},
"status": {}
}
[root@master1 demo]# kubectl get deploy/nginx --export -o yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "2"
creationTimestamp: null
generation: 1
labels:
run: nginx
name: nginx
selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/nginx
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 2
selector:
matchLabels:
run: nginx
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
run: nginx
spec:
containers:
- image: nginx:1.14
imagePullPolicy: Always
name: nginx
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
DNSPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status: {}
[root@master1 demo]# kubectl get deploy/nginx --export -o yaml > my-deploy.yaml
[root@master1 demo]# kubectl explain pods.spec.containers
KIND: Pod
VERSION: v1
RESOURCE: containers <[]Object>
DESCRIPTION:
List of containers belonging to the pod. Containers cannot currently be
added or removed. There must be at least one container in a Pod. Cannot be
updated.
A single application container that you want to run within a pod.
FIELDS:
args <[]string>
Arguments to the entrypoint. The docker image's CMD is used if this is not
provided. Variable references $(VAR_NAME) are expanded using the
container's environment. If a variable cannot be resolved, the reference in
the input string will be unchanged. The $(VAR_NAME) syntax can be escaped
with a double $$, ie: $$(VAR_NAME). Escaped references will never be
expanded, regardless of whether the variable exists or not. Cannot be
updated. More info:
https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell
command <[]string>
Entrypoint array. Not executed within a shell. The docker image's
ENTRYPOINT is used if this is not provided. Variable references $(VAR_NAME)
are expanded using the container's environment. If a variable cannot be
resolved, the reference in the input string will be unchanged. The
$(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME).
Escaped references will never be expanded, regardless of whether the
variable exists or not. Cannot be updated. More info:
https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell
env <[]Object>
List of environment variables to set in the container. Cannot be updated.
envFrom <[]Object>
List of sources to populate environment variables in the container. The
keys defined within a source must be a C_IDENTIFIER. All invalid keys will
be reported as an event when the container is starting. When a key exists
in multiple sources, the value associated with the last source will take
precedence. Values defined by an Env with a duplicate key will take
precedence. Cannot be updated.
image
Docker image name. More info:
https://kubernetes.io/docs/concepts/containers/images This field is
optional to allow higher level config management to default or override
container images in workload controllers like Deployments and StatefulSets.
imagePullPolicy
Image pull policy. One of Always, Never, IfNotPresent. Defaults to Always
if :latest tag is specified, or IfNotPresent otherwise. Cannot be updated.
More info:
https://kubernetes.io/docs/concepts/containers/images#updating-images
lifecycle