官网里面看其它资源的案例

文章插图
部署service
[root@mcwk8s03 demo]#[root@mcwk8s03 demo]# vim mcw-nginx-service.yaml[root@mcwk8s03 demo]# cat mcw-nginx-service.yamlapiVersion: v1kind: Servicemetadata:name: nginx-servicelabels:app: nginxspec:type: NodePortports:- port: 80targetPort: 80selector:app: nginx[root@mcwk8s03 demo]# kubectl create -f mcw-nginx-service.yamlservice/nginx-service created[root@mcwk8s03 demo]# kubectl get svcNAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGEkubernetesClusterIP10.2.0.1<none>443/TCP5d22hnginx-serviceNodePort10.2.0.247<none>80:33851/TCP4s[root@mcwk8s03 demo]# 访问上面刚刚部署的服务 , 版本也是对上的

文章插图
YAML配置文件管理资源 实用技巧? 用run命令生成kubectl run --image=nginx my-deploy -o yaml --dry-run > my-deploy.yaml? 用get命令导出kubectl get my-deploy/nginx -o=yaml --export > my-deploy.yaml? Pod容器的字段拼写忘记了kubectl explain pods.spec.containers用run命令生成 --dry-run生成配置文件[root@mcwk8s03 demo]# kubectl run mcw-nginx-deployment --image=nginx --port=80 --replicas=3 --dry-run#执行部署的命令后面接--dry-run,不会进行部署,可以检查是否有语法错误kubectl 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.deployment.apps/mcw-nginx-deployment created (dry run)[root@mcwk8s03 demo]# kubectl get podNAMEREADYSTATUSRESTARTSAGEnginx-deployment-7fd6966748-mxg8p1/1Running036mnginx-deployment-7fd6966748-pgfgq1/1Running036mnginx-deployment-7fd6966748-wsfj41/1Running036m[root@mcwk8s03 demo]# kubectl get deployNAMEREADYUP-TO-DATEAVAILABLEAGEnginx-deployment3/33337m[root@mcwk8s03 demo]# [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]#
推荐阅读
- 奥比岛2022盛夏之旅活动参与方法
- 流放之路S20卡兰德之湖赛季上线时间说明
- 真正“搞”懂HTTP协议03之时间穿梭
- 网络协议之:redis protocol 详解
- 信号量 C# 多线程访问之 SemaphoreSlim【C# 进阶】
- JavaScript之数组高阶API—reduce
- 奥比岛暗夜袭击第一轮金块失踪之谜通关攻略
- 之八 2流高手速成记:基于Sentinel实现微服务体系下的限流与熔断
- 明日之后幽灵船在哪
- 星之彼端叶灵真伤流怎么搭配阵容