kubernetes之kubectl与YAML详解1( 八 )

[root@mcwk8s03 demo]# kubectl run mcw-nginx-deployment --image=nginx --port=80 --repli=3 --dry-run  #如这条命令,副本数参数写错了就报错了Error: unknown flag: --repli
Examples:# Start a single instance of nginx.kubectl run nginx --image=nginx
 --dry-run 不执行  -o指定输出格式,然后追加到文件中 。这样可以生成yaml配置文件,我们就不需要去网上找模板了 。将导出的模板多余的部分删除掉就行了 。我们也可以获取到json格式的数据
[root@mcwk8s03 demo]# kubectl run mcw-nginx-deployment --image=nginx --port=80 --replicas=3 --dry-run -o yaml >mcwTest.yamlkubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.[root@mcwk8s03 demo]# cat mcwTest.yamlapiVersion: apps/v1kind: Deploymentmetadata:creationTimestamp: nulllabels:run: mcw-nginx-deploymentname: mcw-nginx-deploymentspec:replicas: 3selector:matchLabels:run: mcw-nginx-deploymentstrategy: {}template:metadata:creationTimestamp: nulllabels:run: mcw-nginx-deploymentspec:containers:- image: nginxname: mcw-nginx-deploymentports:- containerPort: 80resources: {}status: {}[root@mcwk8s03 demo]# kubectl run mcw-nginx-deployment --image=nginx --port=80 --replicas=3 --dry-run -o json >mcwTest.jsonkubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.[root@mcwk8s03 demo]# cat mcwTest.json{"kind": "Deployment","apiVersion": "apps/v1","metadata": {"name": "mcw-nginx-deployment","creationTimestamp": null,"labels": {"run": "mcw-nginx-deployment"}},"spec": {"replicas": 3,"selector": {"matchLabels": {"run": "mcw-nginx-deployment"}},"template": {"metadata": {"creationTimestamp": null,"labels": {"run": "mcw-nginx-deployment"}},"spec": {"containers": [{"name": "mcw-nginx-deployment","image": "nginx","ports": [{"containerPort": 80}],"resources": {}}]}},"strategy": {}},"status": {}}[root@mcwk8s03 demo]# 如下,大部分资源都可以用这种方式生成
[root@mcwk8s03 demo]# kubectl api-resourcesNAMESHORTNAMESAPIGROUPNAMESPACEDKINDbindingstrueBindingcomponentstatusescsfalseComponentStatusconfigmapscmtrueConfigMapendpointseptrueEndpointseventsevtrueEventlimitrangeslimitstrueLimitRangenamespacesnsfalseNamespacenodesnofalseNodepersistentvolumeclaimspvctruePersistentVolumeClaimpersistentvolumespvfalsePersistentVolumepodspotruePodpodtemplatestruePodTemplatereplicationcontrollersrctrueReplicationControllerresourcequotasquotatrueResourceQuotasecretstrueSecretserviceaccountssatrueServiceAccountservicessvctrueServicemutatingwebhookconfigurationsadmissionregistration.k8s.iofalseMutatingWebhookConfigurationvalidatingwebhookconfigurationsadmissionregistration.k8s.iofalseValidatingWebhookConfigurationcustomresourcedefinitionscrd,crdsapiextensions.k8s.iofalseCustomResourceDefinitionapiservicesapiregistration.k8s.iofalseAPIServicecontrollerrevisionsappstrueControllerRevisiondaemonsetsdsappstrueDaemonSetdeploymentsdeployappstrueDeploymentreplicasetsrsappstrueReplicaSetstatefulsetsstsappstrueStatefulSettokenreviewsauthentication.k8s.iofalseTokenReviewlocalsubjectaccessreviewsauthorization.k8s.iotrueLocalSubjectAccessReviewselfsubjectaccessreviewsauthorization.k8s.iofalseSelfSubjectAccessReviewselfsubjectrulesreviewsauthorization.k8s.iofalseSelfSubjectRulesReviewsubjectaccessreviewsauthorization.k8s.iofalseSubjectAccessReviewhorizontalpodautoscalershpaautoscalingtrueHorizontalPodAutoscalercronjobscjbatchtrueCronJobjobsbatchtrueJobcertificatesigningrequestscsrcertificates.k8s.iofalseCertificateSigningRequestleasescoordination.k8s.iotrueLeaseeventsevevents.k8s.iotrueEventdaemonsetsdsextensionstrueDaemonSetdeploymentsdeployextensionstrueDeploymentingressesingextensionstrueIngressnetworkpoliciesnetpolextensionstrueNetworkPolicypodsecuritypoliciespspextensionsfalsePodSecurityPolicyreplicasetsrsextensionstrueReplicaSetingressesingnetworking.k8s.iotrueIngressnetworkpoliciesnetpolnetworking.k8s.iotrueNetworkPolicyruntimeclassesnode.k8s.iofalseRuntimeClasspoddisruptionbudgetspdbpolicytruePodDisruptionBudgetpodsecuritypoliciespsppolicyfalsePodSecurityPolicyclusterrolebindingsrbac.authorization.k8s.iofalseClusterRoleBindingclusterrolesrbac.authorization.k8s.iofalseClusterRolerolebindingsrbac.authorization.k8s.iotrueRoleBindingrolesrbac.authorization.k8s.iotrueRolepriorityclassespcscheduling.k8s.iofalsePriorityClasscsidriversstorage.k8s.iofalseCSIDrivercsinodesstorage.k8s.iofalseCSINodestorageclassesscstorage.k8s.iofalseStorageClassvolumeattachmentsstorage.k8s.iofalseVolumeAttachment[root@mcwk8s03 demo]#

经验总结扩展阅读