docker导出日志到本地的方法是什么
317
2022-09-07
【K8S运维知识汇总】第3天2:kubectl详解——声明式资源管理方法
通过陈述式创建的pod资源,获得统一配置清单
[root@hdss7-21 ~]# kubectl get pods nginx-dp-5dfc689474-bqk8w -o yaml -n kube-publicapiVersion: v1kind: Podmetadata: creationTimestamp: "2020-07-01T12:19:34Z" generateName: nginx-dp-5dfc689474- labels: app: nginx-dp pod-template-hash: 5dfc689474 name: nginx-dp-5dfc689474-bqk8w namespace: kube-public ownerReferences: - apiVersion: apps/v1 blockOwnerDeletion: true controller: true kind: ReplicaSet name: nginx-dp-5dfc689474 uid: 109c9920-2fdc-483b-8254-eb10f3e90443 resourceVersion: "77238" selfLink: /api/v1/namespaces/kube-public/pods/nginx-dp-5dfc689474-bqk8w uid: ba5311df-0b9c-41fb-b270-56e0604a54f1spec: containers: - image: harbor.od.com/public/nginx:v1.7.9 imagePullPolicy: IfNotPresent name: nginx resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File volumeMounts: - mountPath: /var/run/secrets/kubernetes.io/serviceaccount name: default-token-vx5v7 readOnly: true dnsPolicy: ClusterFirst enableServiceLinks: true nodeName: hdss7-21.host.com priority: 0 restartPolicy: Always schedulerName: default-scheduler securityContext: {} serviceAccount: default serviceAccountName: default terminationGracePeriodSeconds: 30 tolerations: - effect: NoExecute key: node.kubernetes.io/not-ready operator: Exists tolerationSeconds: 300 - effect: NoExecute key: node.kubernetes.io/unreachable operator: Exists tolerationSeconds: 300 volumes: - name: default-token-vx5v7 secret: defaultMode: 420 secretName: default-token-vx5v7status: conditions: - lastProbeTime: null lastTransitionTime: "2020-07-01T12:19:35Z" status: "True" type: Initialized - lastProbeTime: null lastTransitionTime: "2020-07-01T12:19:36Z" status: "True" type: Ready - lastProbeTime: null lastTransitionTime: "2020-07-01T12:19:36Z" status: "True" type: ContainersReady - lastProbeTime: null lastTransitionTime: "2020-07-01T12:19:35Z" status: "True" type: PodScheduled containerStatuses: - containerID: docker://f5f6ea8d2bf8669efc7daf651a1404869c827a3fd2cbd6f85df8346cfd55de6d image: harbor.od.com/public/nginx:v1.7.9 imageID: docker-pullable://harbor.od.com/public/nginx@sha256:b1f5935eb2e9e2ae89c0b3e2e148c19068d91ca502e857052f14db230443e4c2 lastState: {} name: nginx ready: true restartCount: 0 state: running: startedAt: "2020-07-01T12:19:35Z" hostIP: 10.4.7.21 phase: Running podIP: 172.7.21.2 qosClass: BestEffort startTime: "2020-07-01T12:19:35Z"
查看svc资源对应的配置清单
[root@hdss7-21 ~]# kubectl get svc nginx-dp -o yaml -n kube-publicapiVersion: v1kind: Servicemetadata: creationTimestamp: "2020-07-01T04:12:24Z" labels: app: nginx-dp name: nginx-dp namespace: kube-public resourceVersion: "63896" selfLink: /api/v1/namespaces/kube-public/services/nginx-dp uid: b66f191e-0471-44ec-800a-f3ee6382b40fspec: clusterIP: 192.168.103.156 ports: - port: 80 protocol: TCP targetPort: 80 selector: app: nginx-dp sessionAffinity: None type: ClusterIPstatus: loadBalancer: {}
通过explain获得命令说明
[root@hdss7-21 ~]# kubectl explain service.metadataKIND: ServiceVERSION: v1RESOURCE: metadata
[root@hdss7-21 ~]# vi nginx-ds-svc.yamlapiVersion: v1kind: Servicemetadata: creationTimestamp: "2020-07-01T04:12:24Z" labels: app: nginx-ds name: nginx-ds namespace: defaultspec: ports: - port: 80 protocol: TCP targetPort: 80 selector: app: nginx-ds type: ClusterIP[root@hdss7-21 ~]# kubectl create -f nginx-ds-svc.yaml service/nginx-ds created[root@hdss7-21 ~]# kubectl get svc -n defaultNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes ClusterIP 192.168.0.1
修改资源配置清单
# 离线修改[root@hdss7-21 ~]# vi nginx-ds-svc.yaml [root@hdss7-21 ~]# kubectl apply -f nginx-ds-svc.yaml # 在线修改[root@hdss7-21 ~]# kubectl edit svc nginx-dsservice/nginx-ds edited[root@hdss7-21 ~]# kubectl get svcNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes ClusterIP 192.168.0.1
删除资源配置清单
[root@hdss7-21 ~]# kubectl delete -f nginx-ds-svc.yaml service "nginx-ds" deleted[root@hdss7-21 ~]# kubectl get svc -n defaultNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes ClusterIP 192.168.0.1
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~