[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]#
经验总结扩展阅读
- 丝绸之路开辟于什么朝代
- 流放之路S20卡兰德之湖赛季上线时间说明
- 2023年7月9日适不适合搬新家
- 回门酒的请帖怎么写 诚邀贵宾之请
- 真正“搞”懂HTTP协议03之时间穿梭
- 网络协议之:redis protocol 详解
- 信号量 C# 多线程访问之 SemaphoreSlim【C# 进阶】
- JavaScript之数组高阶API—reduce
- 奥比岛暗夜袭击第一轮金块失踪之谜通关攻略
- 青蟹为什么那么贵