K8Sリソース一覧

A、Kubernetes共通リソース


 

すべてのコンテンツは、オブジェクトが呼び出され、そのリソースがインスタンス化され、抽象リソースをK8S  ポッド、さらにreplicaSet、展開、StatefulSet、DaemonSet、仕事、:ワークロードのタイプのリソース(ワークロード)cronジョブ(ReplicationControllerは、バージョンV1.11に破棄されます)

サービス検出および負荷分散リソースタイプ(S erviceDiscovery LOADBALANCE):サービス、イングレス、...
コンフィギュレーションおよびストレージリソースタイプ:ボリューム(ストレージボリューム)、CSI(コンテナ・ストレージ・インターフェースは、サードパーティのストレージボリュームの様々なを拡張することができます)
ストレージ・ボリュームの特別なタイプ:ConfigMap(リソースタイプセンターを使用するように構成された)、秘密(店舗機密データ)、
DownwardAPI(容器の外部環境へ情報を出力)

クラスタレベルのリソース:名前空間、ノード、役割、ClusterRole 、RoleBinding、ClusterRoleBinding
メタデータタイプのリソースを:HPA、PodTemplate、LimitRange 

第二に、Kubernetesのオブジェクトを理解します

Kubernetesシステムでは、Kubernetesエントリオブジェクトは永続的です。Kubernetesは、クラスタ全体の状態を表現するためにこれらのエントリを使用します。特に、それらは、次の情報について説明します。

  • (とでノード)を実行しているどのようなコンテナアプリケーション
  • リソースは、アプリケーションで使用することができます
  • このように再起動戦略、アップグレード戦略だけでなく、フォールトトレランス政策として、ポリシーの適用に振る舞うする方法

Kubernetesオブジェクトは、「レコードの目標」である - あなたがオブジェクトを作成したら、Kubernetesシステムは、オブジェクトが存在することを確認するために取り組んでいきます。オブジェクトを作成することで、あなたが効果的に、Kubernetesシステムに通知することがどのように見えるのクラスタワークロードを必要とすることができ、これは望ましい状態Kubernetesクラスタです。

 

Kubernetesは、オブジェクトを操作- 、作成、変更、または削除するかどうか- KubernetesのAPIを使用する必要が。使用する場合は  kubectl 、コマンドラインインターフェイスを、例えば、CLIが必要Kubernetes API呼び出しを使用しますが、Kubernetes APIは、プログラムで直接使用することができます。

spec.containers <[]オブジェクト> 
    spec.containers.name <文字列>                       #pod nameフィールドは、オブジェクトの名前がユニークに作成されなければならない、変更することはできません
    spec.containers.image <文字列>パス#リポジトリミラー/ ミラー名前:ラベルはミラー
    spec.containers.image.imagePullPolicy   <文字列>         ダウンロード戦略#ミラー。3があります。常に(常に倉庫のダウンロードへ)、ネバーは(倉庫からダウンロードしていない)、IfNotPresentは(ローカル倉庫のダウンロードに行くされていない場合)            
        、デフォルトではされてラベルが最新のミラー化されている場合は、「IfNotPresentは」しかし、それは常になります」。オブジェクトが作成されると常に、そして、フィールドを変更することが許可されている
    開放容器ポートは、システムのために使用される容器のネットワーク接続に関する追加情報を提供することができる本明細書に開示されたポートのspec.containers.ports :.#リストが、主に情報を提供しますここでは、ポートを妨げないポートが開いて指定しないでください。デフォルトでは、任意の容器を監視する「0.0.0.0 ポート」アドレスは、ネットワークからアクセスすることができ
        spec.containers.ports.containerPort <整数> -required-    ポートは全く影響にさらされているか否かに関する付加情報のみが露出ポート、#pod 
        spec.containers.ports.hostPort <整数>    ホスト位でオープンポート
        spec.containers.ports.protocolの<string> ポートをプロトコル
        spec.containers.ports.hostIPは    <String>は    #指定したバインドにホストが
    spec.containers.command <[]文字列> プログラムの実行#は、ドッキングウィンドウのentrypiontと同様に、コマンドは、シェルで実行しない場合このフィールドは、そのentrypiontに動作指令をミラーリングドッカーない場合
    spec.containers.args <[]の文字列>   ミラードッカーに#パスパラメータこのフィールドが定義されている場合、ドッカーミラーCMDコマンドは、基準変数と、実行されません参考まで(VAR_NAME)$$あなたは道のコマンドリファレンスを使用したい場合は、私たちが使用する必要があり、$(VAR_NAME)形式の参照を使用する方法
コマンドと引数の#公式文書リンク:HTTPS:// kubernetes.io/docs/tasks/inject -data-アプリケーション定義/ +コマンドを   引数コンテナ/
pod.spec.containers.volumeMounts 
  pod.spec.containers.volumeMounts.name 
  pod.spec.containers.volumeMounts.mountPath#コンテナパスのストレージ・ボリュームを取り付けることができる、経路を含めることはできません「:」シンボル
  pod.spec.containers。 volumeMounts.subPathの#パスがコンテナのストレージボリュームに装着することができると、ファイルのマウントポイントをカバーしていない
  pod.spec.containers.volumeMounts.readOnly#は読み取り専用の場合、デフォルトはfalseにある
pod.spec.containers.resources 
  スペック.containers.resources.limits#リソースの制約
    spec.containers.resources.limits.cpu:CPUの制限、あなたは簡単にコンテナが停止されることはありません超えることができ
    spec.containers.resources.limits.memoryを:メモリの制限、超えることはできません。もしコンテナは他のマシンに十分な資源で終了、またはスケジュールすることができる上
  spec.containers.resources.requests#リソース要件
    spec.containers.resources.requests.cpu:CPU要求、スケジューリングはCPUリソースに基づいている以上のことができます
    spec.containers.resources.requests.memory:メモリ要求を超えることがあり、メモリリソースに応じて予定されている。超えた場合しかし、コンテナはノードたときにメモリ不足に洗浄することができます

 

 

三、YAML文法

1、基本的な文法

K :(空間)V:キーと値のペアのペアを指定する(スペースが存在しなければなりません)。

スペースインデント制御階層の、一方は、同じレベル左揃えデータであるれている限り

 
 
 
 
 
サーバー
    ポート8081
    パス /ハロー
 

そして、属性値は大文字と小文字が区別されます。

 

図2に示すように、値が書き込ま

リテラル:一般的な値(数値、文字列、ブール)

K:V:文字通り直接書き込みます。

単一または二重引用符では、デフォルトの文字列ません。

「」:二重引用符、特殊文字の文字列が逃れられないだろう。特殊文字自体が意思の望むように

名前: "zhangsan \ nはリージ":出力; zhangsanラップリージ

「」:シングルクオート、最終的には、普通の文字列データを特殊文字を特殊文字をエスケープします

名前: 'zhangsan \ nはリージ':出力; zhangsan \ nはリージ

 

オブジェクト、マップ(属性と値)(キーと値のペア):

K:V:次の行を記述するオブジェクトの属性と値の関係、ノートインデント

オブジェクトまたはK:V方法

 
 
 
 
 
友人
lastNameの zhangsan
年齢20
 

インライン言葉遣い:

 
 
 
 
 
友人:{ lastNameの zhangsan 年齢18 }
 

 

アレイ(リスト、セット):

と - 配列値の要素を表します

 
 
 
 
 
ペット
-
 - dog
 - pig
 

行内写法

 
 
 
 
 
pets: [cat,dog,pig]
 

 

 

四 资源清单详解

资源清单格式

apiVersion: group/apiversion # 如果没有给定 group 名称,那么默认为 core,可以使用 kubectl api- versions # 获取当前 k8s 版本上所有的 apiVersion 版本信息( 每个版本可能不同 )
kind:    #资源类别 metadata:   #资源元数据
name namespace lables
annotations    # 主要目的是方便用户阅读查找
spec: # 期望的状态(disired state)
status:# 当前状态,本字段有 Kubernetes 自身维护,用户不能去定义

 

资源清单的常用命令

获取 apiversion 版本信息

[root@k8s-master01 ~]# kubectl api-versions admissionregistration.k8s.io/v1beta1 apiextensions.k8s.io/v1beta1 apiregistration.k8s.io/v1 apiregistration.k8s.io/v1beta1
apps/v1
......(以下省略)

 

获取资源的 apiVersion 版本信息

[root@k8s-master01 ~]# kubectl explain pod KIND:    Pod
VERSION: v1
.....(以下省略)

[root@k8s-master01 ~]# kubectl explain Ingress KIND:    Ingress
VERSION: extensions/v1beta1

 

获取字段设置帮助文档

[root@k8s-master01 ~]# kubectl explain pod KIND:    Pod
VERSION: v1

DESCRIPTION:
Pod is a collection of containers that can run on a host. This resource is created by clients and scheduled onto hosts.

FIELDS:
apiVersion    <string>
........
........

 

字段配置格式

apiVersion <string>    #表示字符串类型
metadata <Object>
labels <map[string]string>  #表示由k:v组成的映射
finalizers <[]string> #表示字串列表 ownerReferences <[]Object> #表示对象列表 hostPID <boolean>    #布尔类型
priority <integer>    #整型
name <string> -required-    #如果类型后面接 -required-,表示为必填字段

 

通过定义清单文件创建 Pod

kubectl get pod xx.xx.xx -o yaml
<!--使用 -o 参数 加 yaml,可以将资源的配置以 yaml的格式输出出来,也可以使用json,输出为json格式-->

 

apiVersion: v1 
kind: Pod
metadata: name: pod
-demo
namespace: default
labels: app: myapp

spec: containers:
- name: myapp-1 image: hub.atguigu.com/library/myapp:v1 - name: busybox-1
image: busybox:latest
command:
- "/bin/sh" - "-c" - "sleep 3600"

 

五、使用配置清单创建自主式Pod资源 

[root@k8s-master mnt]# cat pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  containers:
  - name: app
    image: nginx

[root@k8s-master mnt]#

 

 创建Pod

[root@k8s-master ~]# kubectl explain pod
KIND:     Pod
VERSION:  v1

DESCRIPTION:
     Pod is a collection of containers that can run on a host. This resource is
     created by clients and scheduled onto hosts.

FIELDS:
   apiVersion   <string>
     APIVersion defines the versioned schema of this representation of an
     object. Servers should convert recognized schemas to the latest internal
     value, and may reject unrecognized values. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#resources

   kind <string>
     Kind is a string value representing the REST resource this object
     represents. Servers may infer this from the endpoint the client submits
     requests to. Cannot be updated. In CamelCase. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds

   metadata     <Object>
     Standard object's metadata. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata

   spec <Object>
     Specification of the desired behavior of the pod. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status

   status       <Object>
     Most recently observed status of the pod. This data may not be up to date.
     Populated by the system. Read-only. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status

[root@k8s-master ~]# kubectl explain pod.apiVersion
KIND:     Pod
VERSION:  v1

FIELD:    apiVersion <string>

DESCRIPTION:
     APIVersion defines the versioned schema of this representation of an
     object. Servers should convert recognized schemas to the latest internal
     value, and may reject unrecognized values. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
-rw-r--r--  1 root root 134 12月  1 22:05 pod.yaml
[root@k8s-master mnt]# kubectl create -f pod.yaml
pod/myapp-pod created
[root@k8s-master mnt]# kubectl get pod -o wide
NAME                           READY   STATUS             RESTARTS   AGE     IP            NODE         NOMINATED NODE   READINESS GATES
myapp-pod                      1/1     Running            0          13s     10.244.1.5    k8s-node02   <none>           <none>
nginx-test-754bbf667c-q4z25    1/1     Running            0          4d23h   10.244.1.2    k8s-node02   <none>           <none>
nginx-test1-64f9f796d-wvvrz    0/1     ImagePullBackOff   0          3d      10.244.2.7    k8s-node01   <none>           <none>
nginx-test2-77b9dcf788-gxj76   1/1     Running            0          3d      10.244.1.3    k8s-node02   <none>           <none>
nginx-test3-d9ff9874d-ss6ft    0/1     ImagePullBackOff   0          2d23h   10.244.2.9    k8s-node01   <none>           <none>
nginx-test4-685dfcc98d-xx8h6   1/1     Running            0          2d23h   10.244.1.4    k8s-node02   <none>           <none>
nginx-test5-55fccd6c76-cxgsb   0/1     ImagePullBackOff   0          34m     10.244.2.11   k8s-node01   <none>           <none>
[root@k8s-master mnt]# kubectl describe myapp-pod
error: the server doesn't have a resource type "myapp-pod"
[root@k8s-master mnt]# kubectl describe pod  myapp-pod
Name:         myapp-pod
Namespace:    default
Priority:     0
Node:         k8s-node02/192.168.180.103
Start Time:   Sun, 01 Dec 2019 22:06:21 +0800
Labels:       app=myapp
Annotations:  <none>
Status:       Running
IP:           10.244.1.5
Containers:
  app:
    Container ID:   docker://13279a22d067e98bda1e25ebb4ff1221412d24325ff47a2b577a17294856cba8
    Image:          nginx
    Image ID:       docker-pullable://192.168.180.105:1180/topcheer/nginx@sha256:189cce606b29fb2a33ebc2fcecfa8e33b0b99740da4737133cdbcee92f3aba0a
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Sun, 01 Dec 2019 22:06:32 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-hd24d (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-hd24d:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-hd24d
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age   From                 Message
  ----    ------     ----  ----                 -------
  Normal  Scheduled  55s   default-scheduler    Successfully assigned default/myapp-pod to k8s-node02
  Normal  Pulling    51s   kubelet, k8s-node02  Pulling image "nginx"
  Normal  Pulled     44s   kubelet, k8s-node02  Successfully pulled image "nginx"
  Normal  Created    44s   kubelet, k8s-node02  Created container app
  Normal  Started    44s   kubelet, k8s-node02  Started container app

 

おすすめ

転載: www.cnblogs.com/dalianpai/p/11968520.html