{"id":8669,"date":"2024-05-31T08:01:05","date_gmt":"2024-05-31T00:01:05","guid":{"rendered":""},"modified":"2024-05-31T08:01:05","modified_gmt":"2024-05-31T00:01:05","slug":"kubernetes yaml\u751f\u6210\u5de5\u5177_k8s\u548cdocker\u533a\u522b","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8669.html","title":{"rendered":"kubernetes yaml\u751f\u6210\u5de5\u5177_k8s\u548cdocker\u533a\u522b"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u58f0\u660e<\/strong>\uff1a\u672c\u6587\u51fa\u81ea CNCF\uff0c\u5e16\u5b50\u6700\u521d\u53d1\u8868\u4e8e ARMO\uff0c\u7531\u7814\u53d1\u526f\u603b\u88c1\u517c\u8054\u5408\u521b\u59cb\u4eba Ben Hirschberg \u64b0\u5199\uff0c\u5df2\u83b7\u5f97\u6388\u6743\u3002<\/p>\n

\u611f\u8c22 \u5c71\u6cb3\u5df2\u65e0\u6059 \u6574\u7406\uff0c \u897f\u72e9xs \u6821\u5bf9\u3002\u4ee5\u4e0b\u4e3a\u7ffb\u8bd1\u5168\u6587\uff0c\u5206\u4eab\u7ed9\u5927\u5bb6 \u3002<\/p>\n

\u5c3d\u7ba1 Kubernetes \u8d8a\u6765\u8d8a\u53d7\u6b22\u8fce\uff0c\u4f46\u5b83\u4ecd\u7136\u6709\u4e00\u5b9a\u7684\u5b66\u4e60\u96be\u5ea6\uff0c\u8fd9\u4f7f\u5f97\u5f88\u96be\u91c7\u7528\u8fd9\u9879\u6280\u672f\u3002\u5728\u5feb\u8282\u594f\u7684\u8f6f\u4ef6\u5f00\u53d1\u9886\u57df\u4e2d\uff0c\u90a3\u4e9b\u4e0d\u80fd\u514b\u670d\u521d\u671f\u969c\u788d\u7684\u4eba\u5f80\u5f80\u4f1a\u88ab\u7529\u5728\u8eab\u540e\u3002<\/p>\n

\u672c\u6587\u5c06\u4ecb\u7ecd Kubernetes \u5bf9\u8c61\u914d\u7f6e\u7684 YAML \u6587\u4ef6\u3002YAML \u63d0\u4f9b\u4e86\u4e00\u79cd\u4ee5\u58f0\u660e\u5f0f\u914d\u7f6e Kubernetes \u5e94\u7528\u7a0b\u5e8f\u7684\u65b9\u6cd5\uff0c\u8fd9\u4e9b\u58f0\u660e\u6027\u6587\u4ef6\u5141\u8bb8\u60a8\u6709\u6548\u5730\u6269\u5c55\u548c\u7ba1\u7406\u5e94\u7528\u7a0b\u5e8f\u3002\u5982\u679c\u4e0d\u4e86\u89e3 Kubernetes \u5bf9\u8c61\u7684\u57fa\u672c\u914d\u7f6e\uff0c\u5f88\u5bb9\u6613\u9677\u5165\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u7684\u9677\u9631\uff0c\u800c\u65e0\u6cd5\u4e86\u89e3\u4ed6\u4eec\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002<\/p>\n

\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cYAML \u548c JSON \u90fd\u53ef\u4ee5\u7528\u4e8e Kubernetes \u7684\u914d\u7f6e\uff0c\u5c3d\u7ba1\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b YAML \u88ab\u8ba4\u4e3a\u66f4\u96be\u7f16\u5199\uff0c\u4f46\u5b83\u66f4\u52a0\u7d27\u51d1\u3002\u5f53\u8003\u8651\u5230\u9700\u8981\u4e3a\u5927\u578b\u5e94\u7528\u7a0b\u5e8f\u7ba1\u7406\u6240\u6709 YAML \u6587\u4ef6\u65f6\uff0c\u8fd9\u662f\u4e00\u4e2a\u5f88\u5927\u7684\u4f18\u52bf\u3002<\/p>\n

\u603b\u7684\u6765\u8bf4\uff0cYAML \u66f4\u6613\u4e8e\u7528\u6237\u4f7f\u7528\uff0c\u7d27\u51d1\u7684\u7279\u6027\u5141\u8bb8\u60a8\u5bf9 \u76f8\u5173\u7684 Kubernetes \u5bf9\u8c61\u8fdb\u884c\u5206\u7ec4 \uff0c\u4ece\u800c\u51cf\u5c11\u6240\u9700\u6587\u4ef6\u7684\u6570\u91cf\u3002\u8fd9\u662f\u56e0\u4e3a YAML \u7684\u8bbe\u8ba1\u76ee\u6807\u662f\u63d0\u9ad8\u53ef\u8bfb\u6027\u5e76\u63d0\u4f9b\u66f4\u5b8c\u6574\u7684\u4fe1\u606f\u6a21\u578b\u3002\u5b83\u53ef\u4ee5\u7b80\u5355\u5730\u770b\u4f5c\u662f JSON \u7684\u6f14\u53d8\u3002<\/p>\n

Kubernetes \u7684 YAML<\/h3>\n

\u4e3a\u4e86\u5f00\u59cb\u4f7f\u7528 Kubernetes \u7684 YAML\uff0c\u6211\u4eec\u5c06\u56de\u987e YAML \u7684\u57fa\u672c\u7ed3\u6784\u7c7b\u578b\uff0c\u5982\u4e0b\u8868\u6240\u793a\uff1a<\/p>\n\n\n\n\n\n
\u952e\/\u5b57\u6bb5-\u503c \u5bf9\uff08Key\/Field-Value Pair\uff09<\/th>\n\u5217\u8868\uff08List\uff09<\/th>\n\u96c6\u5408\uff08Map\uff09<\/th>\n<\/tr>\n<\/thead>\n
app: redis
role: replica
tier: backend<\/td>\n
containers:
\u2013 name: webserver1
\u2013 name: database-server
\u2013 name: rss-reader<\/td>\n
containers:
\u2013 name: webserver1
image: nginx:1.6
ports:
\u2013 containerPort:80
\u2013 name: database-server
image: mysql-3.2
ports:
\u2013 containerPort:3306
\u2013 name: rss-reader
image: rss-php-nginx:2.8
ports:
\u2013 containerPort:86<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5728\u4e3a Kubernetes \u7f16\u5199 YAML \u6587\u4ef6\u65f6\uff0c\u5fc5\u987b\u5b58\u5728\u56db\u4e2a\u5fc5\u9700\u7684\u5b57\u6bb5\uff1aAPI \u7248\u672c\uff08apiVersion\uff09\u3001\u7c7b\u578b\uff08kind\uff09\u3001\u5143\u6570\u636e\uff08metadata\uff09\u548c\u89c4\u8303\uff08spec\uff09\u3002<\/p>\n

apiVersion<\/h4>\n

\u8be5\u5b57\u6bb5\u5f15\u7528 API\uff0c\u7528\u4e8e\u521b\u5efa\u8981\u5b9a\u4e49\u7684 Kubernetes \u5bf9\u8c61\u3002Kubernetes \u63d0\u4f9b\u4e86\u5404\u79cd API\uff0c\u4f7f\u60a8\u80fd\u591f\u521b\u5efa\u4e0d\u540c\u7684 Kubernetes \u5bf9\u8c61\u3002\u4f8b\u5982\uff1aapiVersion: v1<\/code> \u5305\u542b\u4e86\u8bb8\u591a\u6838\u5fc3\u5bf9\u8c61\u3002<\/p>\n

apiVersion: v1<\/code> \u901a\u5e38\u88ab\u8ba4\u4e3a\u662f Kubernetes \u53d1\u5e03\u7684\u7b2c\u4e00\u4e2a\u7a33\u5b9a\u7248\u672c\u3002\u53e6\u4e00\u4e2a\u6d41\u884c\u7684API \u7248\u672c\u662f apps\/v1<\/code>\uff0c\u5b83\u91c7\u7528\u4e86 v1<\/code> \u4e2d\u7684\u5bf9\u8c61\uff0c\u5e76\u63d0\u4f9b\u4e86 Deployments \u548c ReplicaSets \u7b49 \u5173\u952e\u529f\u80fd\u3002<\/p>\n

\u56e0\u6b64\uff0c\u5728\u6211\u4eec\u7684 YAML \u6587\u4ef6\u4e2d\uff0c\u5b9a\u4e49 API \u7248\u672c\u53ef\u4ee5\u662f\uff1a<\/p>\n

apiVersion<\/span>:<\/span> v1\n<\/code><\/pre>\n

kind<\/h4>\n

kind<\/code> \u5141\u8bb8\u60a8\u6307\u5b9a\u8981\u5b9a\u4e49\u7684 Kubernetes \u5bf9\u8c61\u7684\u7c7b\u578b\u3002\u60a8\u5728\u8fd9\u4e2a\u5b57\u6bb5\u4e2d\u8981\u6307\u5b9a\u7684\u5bf9\u8c61\u5c06\u88ab\u94fe\u63a5\u5230\u60a8\u4e4b\u524d\u6307\u5b9a\u7684 apiVersion<\/code>\uff0c\u56e0\u4e3a API \u7248\u672c\u5b57\u6bb5\u5141\u8bb8\u4f60\u8bbf\u95ee\u4e0d\u540c\u7c7b\u578b\u7684\u5bf9\u8c61\u53ca\u5176\u7279\u5b9a\u7684\u5b9a\u4e49\u3002\u53ef\u4ee5\u5b9a\u4e49\u7684\u5bf9\u8c61\u7c7b\u578b\u6709 Pod\u3001Service \u548c DaemonSet\u3002<\/p>\n

\u56e0\u6b64\uff0c\u4e3a\u4e86\u5b9a\u4e49\u4e00\u4e2a pod \u5bf9\u8c61\uff0c\u5728\u6307\u5b9a apiVersion \u4e4b\u540e\uff0c\u6211\u4eec\u5c06\u6307\u5b9a kind \u5b57\u6bb5\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

apiVersion<\/span>:<\/span> v1\nkind<\/span>:<\/span> Pod\n<\/code><\/pre>\n

metadata<\/h4>\n

\u5728\u6307\u5b9a\u8981\u5b9a\u4e49\u7684\u5bf9\u8c61\u7c7b\u578b\u4e4b\u540e\uff0cmetadata<\/code> \u5b57\u6bb5\u5c06\u4e3a\u8be5\u7279\u5b9a\u5bf9\u8c61\u63d0\u4f9b\u552f\u4e00\u5c5e\u6027\u3002\u8fd9\u53ef\u80fd\u5305\u62ec name<\/code>\u3001uuid<\/code> \u548c namespace<\/code> \u7b49\u5b57\u6bb5\u3002\u8fd9\u4e9b\u5b57\u6bb5\u6307\u5b9a\u7684\u503c\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u8be5\u5bf9\u8c61\u7684\u4e0a\u4e0b\u6587\uff0c\u5e76\u4e14\u5b83\u4eec\u4e5f\u53ef\u4ee5\u88ab\u5176\u4ed6\u5bf9\u8c61\u5f15\u7528\u3002\u56e0\u6b64\uff0c\u8fd9\u4e2a\u5b57\u6bb5\u5141\u8bb8\u6211\u4eec\u6307\u5b9a\u5bf9\u8c61\u7684\u6807\u8bc6\u7b26\u5c5e\u6027\u3002<\/p>\n

\u4f8b\u5982\uff1a\u5982\u679c\u6211\u4eec\u6b63\u5728\u6784\u5efa\u4e00\u4e2a spring \u5e94\u7528\u7a0b\u5e8f\uff0c\u6211\u4eec\u7684 pod \u7684 name \u503c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

apiVersion<\/span>:<\/span> v1\nkind<\/span>:<\/span> Pod\nmetadata<\/span>:<\/span>\n    name<\/span>:<\/span> spring-<\/span>pod\n<\/code><\/pre>\n

spec<\/h4>\n

spec<\/code> \u5b57\u6bb5\u5141\u8bb8\u6211\u4eec\u4e3a\u6211\u4eec\u6784\u5efa\u7684\u5bf9\u8c61\u5b9a\u4e49\u671f\u671b\u503c\u3002\u5b83\u7531\u6240\u6709\u9488\u5bf9\u5b9a\u4e49\u5bf9\u8c61\u64cd\u4f5c\u7684\u952e\u503c\u5bf9\u7ec4\u6210\u3002\u5c31\u50cf\u5bf9\u8c61\u672c\u8eab\u4e00\u6837\uff0c\u5bf9\u8c61\u7684\u89c4\u8303\u4f9d\u8d56\u4e8e\u4e4b\u524d\u6307\u5b9a\u7684 API \u7248\u672c\u3002\u56e0\u6b64\uff0c\u4e0d\u540c\u7684 API \u7248\u672c\u53ef\u80fd\u5305\u542b\u76f8\u540c\u7684\u5bf9\u8c61\uff0c\u4f46\u5bf9\u8c61\u53ef\u4ee5\u5b9a\u4e49\u7684\u89c4\u8303\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\u3002<\/p>\n

\u5982\u679c\u6211\u4eec\u7ee7\u7eed\u6211\u4eec\u6784\u5efa spring \u5e94\u7528\u7a0b\u5e8f\u7684 pod \u5bf9\u8c61\u793a\u4f8b\uff0c\u6211\u4eec\u7684 spec \u5b57\u6bb5\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

apiVersion<\/span>:<\/span> v1\nkind<\/span>:<\/span> Pod\nmetadata<\/span>:<\/span>\n    name<\/span>:<\/span> spring-<\/span>pod\n    containers<\/span>:<\/span>\n    \u2013 image<\/span>:<\/span> armo\/springapp:<\/span>example\nspec<\/span>:<\/span>\n      name<\/span>:<\/span> spring-<\/span>app\n      ports<\/span>:<\/span>\n      \u2013 containerPort<\/span>:<\/span> 80<\/span>\n        protocol<\/span>:<\/span> TCP\n<\/code><\/pre>\n

\u5728\u4e0a\u9762\u7684\u6700\u540e\u4e00\u4e2a\u793a\u4f8b\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 API v1 \u521b\u5efa\u4e00\u4e2a Pod \u5bf9\u8c61\uff0c\u6211\u4eec\u5c06\u5176\u547d\u540d\u4e3aspring-pod<\/code>\u3002\u6309\u7167\u8fd9\u4e2a\u89c4\u8303\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u7684\u7aef\u53e3\u4e3a 80\uff0c\u4f7f\u7528\u7684\u955c\u50cf\u4e3a armo\/springapp:example<\/code>\u3002<\/p>\n

\u4e0b\u56fe\u6bd4\u8f83\u4e86 JSON<\/code> \u548c YAML<\/code> \u4e2d\u7684\u914d\u7f6e\u3002\u6b63\u5982\u60a8\u6240\u770b\u5230\u7684\uff0cYAML\u66f4\u52a0\u7b80\u6d01\u6613\u8bfb\u3002<\/p>\n

\"kubernetes<\/p>\n

\u7ba1\u7406 YAML \u6587\u4ef6\u7684\u7b56\u7565<\/h3>\n

\u73b0\u5728\u6211\u4eec\u5df2\u7ecf\u6784\u5efa\u4e86 Kubernetes \u7684 YAML \u6587\u4ef6\uff0c\u8ba9\u6211\u4eec\u770b\u770b\u8fdb\u4e00\u6b65\u52a0\u901f\u6784\u5efa Kubernetes \u5e94\u7528\u7a0b\u5e8f\u7684\u4e00\u4e9b\u7b56\u7565\u3002<\/p>\n

YAML \u7684\u7248\u672c\u63a7\u5236<\/h4>\n

\u5982\u4e0a\u6240\u8ff0\uff0c\u4f7f\u7528 YAML \u5b57\u6bb5\u5141\u8bb8\u60a8\u4ee5\u58f0\u660e\u65b9\u5f0f\u7ba1\u7406 Kubernetes \u5e94\u7528\u7a0b\u5e8f\u3002\u8fd9\u4e9b YAML \u6587\u4ef6\u53ef\u4ee5\u5b58\u50a8\u5728\u4e00\u4e2a\u516c\u5171\u76ee\u5f55\u4e2d\uff0c\u5e76\u4e14\u53ef\u4ee5\u4f7f\u7528 kubectl apply -f <directory><\/code> \u6765\u5e94\u7528\u5b83\u4eec\u3002<\/p>\n

\u8fd9\u76f8\u5f53\u7b80\u5355\u3002\u4f46\u662f\uff0c\u968f\u7740\u5e94\u7528\u7a0b\u5e8f\u7684\u6f14\u53d8\u548c\u5bf9 Kubernetes \u5bf9\u8c61\u5b9a\u4e49\u7684\u66f4\u6539\uff0c\u60a8\u5fc5\u987b\u8003\u8651\u5f53\u524d\u90e8\u7f72\u7684\u662f\u54ea\u4e2a\u7248\u672c\u548c\u66f4\u6539\u3002\u8fd9\u662f\u56e0\u4e3a\uff1a\u5982\u679c\u6ca1\u6709\u7248\u672c\u63a7\u5236\uff0c\u60a8\u53ef\u80fd\u65e0\u6cd5\u56de\u6eda\u5230\u4e4b\u524d\u7684\u955c\u50cf\uff0c\u800c\u4e4b\u524d\u7684\u955c\u50cf\u53ef\u80fd\u4f1a\u6bd4\u65b0\u8fd0\u884c\u7684\u6620\u50cf\u66f4\u52a0\u7a33\u5b9a\u3002<\/p>\n

\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0 YAML \u7684\u7248\u672c\u63a7\u5236\uff0c\u5b83\u4eec\u7684\u590d\u6742\u6027\u548c\u6613\u7ba1\u7406\u6027\u5404\u4e0d\u76f8\u540c\u3002\u8fd9\u53ef\u80fd\u9700\u8981\u5728 YAML \u4e2d\u4f7f\u7528\u7b80\u5355\u7684\u6807\u8bb0\u4ee5\u53ca\u624b\u52a8\u6267\u884c kubectl \u547d\u4ee4\uff0c\u6216\u8005\u9700\u8981\u4f7f\u7528\u7279\u6b8a\u5de5\u5177\uff0c\u5982 Helm\u3002\u53d7\u9650\u4e8e\u672c\u6587\u7684\u8bb2\u89e3\u8303\u56f4\uff0c\u65e0\u6cd5\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u4f46\u662f\u503c\u5f97\u4e00\u63d0\u7684\u662f\uff1a\u7248\u672c\u63a7\u5236\u662f\u4e00\u9879\u91cd\u8981\u7684\u5b9e\u8df5\u3002<\/p>\n

\u7ba1\u7406 Secrets<\/h4>\n

\u5728\u5e94\u7528\u7a0b\u5e8f\u7684\u6574\u4e2a\u751f\u547d\u5468\u671f\u4e2d\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5229\u7528\u9690\u79c1\u6570\u636e\u6765\u652f\u6301\u5176\u529f\u80fd\u3002\u8fd9\u53ef\u80fd\u5305\u62ec\u5bc6\u7801\u3001\u7528\u6237\u4fe1\u606f\uff0c\u751a\u81f3\u4fe1\u7528\u5361\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n

\u5728\u5b9a\u4e49 Kubernetes \u5bf9\u8c61\u65f6\uff0c\u60a8\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u6570\u636e\u76f4\u63a5\u4f5c\u4e3a\u53d8\u91cf\u653e\u5165 YAML \u6587\u4ef6\u4e2d\u3002\u7136\u800c\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u91cd\u5927\u7684\u5b89\u5168\u6f0f\u6d1e\uff0c\u5e76\u4e14\u589e\u52a0\u4e86\u8fd9\u4e9b\u6570\u636e\u843d\u5165\u574f\u4eba\u4e4b\u624b\u7684\u53ef\u80fd\u6027\u3002\u56e0\u6b64\uff0c\u5efa\u8bae\u4f7f\u7528 Kubernetes \u63d0\u4f9b \u7684Secrets \u5bf9\u8c61\u4ee5\u53ca\u79d8\u5bc6\u7ba1\u7406\u5de5\u5177\u3002<\/p>\n

\u5f53\u5229\u7528 Secrets \u5bf9\u8c61\u65f6\uff0cpod \u5fc5\u987b\u5f15\u7528 Secret\u3002\u8fd9\u5c31\u662f\u6211\u4eec\u4f7f\u7528 metadata \u5b57\u6bb5\u7684\u5730\u65b9\u3002pod \u5c06\u4f7f\u7528Secret name<\/code>\u5b57\u6bb5\uff0c\u5176\u4e2dSecret<\/code>\u5bf9\u8c61\u7684\u540d\u79f0\u5c06\u662f\u4e00\u4e2a\u6709\u6548\u7684DNS\u5b50\u57df\u540d<\/code>\u3002<\/p>\n

\u5728\u5229\u7528 Secrets \u5bf9\u8c61\u65f6\uff0cpod \u5fc5\u987b\u5f15\u7528 Secret\u3002\u6240\u4ee5\uff0c\u8fd9\u5c31\u662f\u6211\u4eec\u4f7f\u7528\u5143\u6570\u636e\u5b57\u6bb5\u7684\u5730\u65b9\u3002pod \u5c06\u4f7f\u7528 Secret name \u5b57\u6bb5\uff0c\u5176\u4e2d Secret \u5bf9\u8c61\u7684\u540d\u79f0\u5c06\u662f\u6709\u6548\u7684 DNS \u5b50\u57df\u540d\u3002<\/p>\n

\u4e0b\u9762\u662f\u4e00\u4e2a\u5b9a\u4e49 Secrets \u5bf9\u8c61\u7684\u793a\u4f8b\uff1a<\/p>\n

apiVersion<\/span>:<\/span> v1\nkind<\/span>:<\/span> Secret\nmetadata<\/span>:<\/span>\n  name<\/span>:<\/span> mysecret\ntype<\/span>:<\/span> Opaque\ndata<\/span>:<\/span>\n  username<\/span>:<\/span> YWRtaW4=\n  password<\/span>:<\/span> MWYyZDFlMmU2N2Rm\n<\/code><\/pre>\n

\u4e00\u5b9a\u8981\u6ce8\u610f Secret \u7c7b\u578b\u3002\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06 Secrets \u7c7b\u578b\u6307\u5b9a\u4e3a Opaque\uff08\u4e0d\u900f\u660e\uff09\u3002\u8fd9\u662f Secret \u5bf9\u8c61\u7684\u9ed8\u8ba4\u7c7b\u578b\u3002\u53e6\u4e00\u79cd Secrets \u7c7b\u578b\u662f kubernetes.io\/service-account-token\uff0c\u7528\u4e8e\u5b58\u50a8\u670d\u52a1\u5e10\u6237 token\u3002<\/p>\n

\u66f4\u591a\u5173\u4e8e \u5982\u4f55\u7ba1\u7406 Kubernetes \u9690\u79c1 \u7684\u8be6\u7ec6\u4fe1\u606f\u53ef\u4ee5\u53c2\u8003 ARMO \u4e2d\u7684\u8d44\u6599\u3002<\/p>\n

YAML \u6a21\u677f<\/h4>\n

YAML \u6a21\u677f\u7684\u76ee\u7684\u662f\u901a\u8fc7\u5728 Kubernetes \u5e94\u7528\u7a0b\u5e8f\u4e2d\u590d\u7528 YAML \u6587\u4ef6\u6765\u51cf\u5c11\u6211\u4eec\u5fc5\u987b\u7f16\u5199\u548c\u7ba1\u7406\u7684 YAML \u6587\u4ef6\u7684\u6570\u91cf\u3002\u4f8b\u5982\uff0c\u8ba9\u6211\u4eec\u8003\u8651\u4e0b\u9762\u7684 pod \u5b9a\u4e49\uff1a<\/p>\n

apiVersion<\/span>:<\/span> v1\nkind<\/span>:<\/span> Pod\nmetadata<\/span>:<\/span>\n  name<\/span>:<\/span> spring-<\/span>pod\nspec<\/span>:<\/span>\n  containers<\/span>:<\/span>\n  \u2013 image<\/span>:<\/span> armo\/springapp:<\/span>example\n    name<\/span>:<\/span> spring-<\/span>app\n    env<\/span>:<\/span>\n    \u2013 name<\/span>:<\/span> eu-<\/span>west-<\/span>1<\/span>\n      value<\/span>:<\/span> postgres:<\/span>\/\/db_url:<\/span>5432<\/span>\n<\/code><\/pre>\n

\u8fd9\u4e2a pod \u4f4d\u4e8e eu-west-1 \u533a\u57df\u3002\u4f46\u662f\uff0c\u5982\u679c\u6211\u4eec\u60f3\u4e3a\u7f8e\u56fd\u7684\u5ba2\u6237\u90e8\u7f72 us-west-1\uff0c\u6211\u4eec\u5c06\u4e0d\u5f97\u4e0d\u7f16\u5199\u4e00\u4e2a\u65b0\u7684 YAML \u6587\u4ef6\uff0c\u56e0\u4e3a\u6211\u4eec\u4f7f\u7528\u7684\u662f\u786c\u7f16\u7801\u503c\u3002<\/p>\n

\u8fd9\u4e2a\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848\u662f YAML \u6a21\u677f\uff0c\u5b83\u5141\u8bb8\u6211\u4eec\u4f7f\u7528\u4e0d\u540c\u7684\u503c\u590d\u7528 YAML \u6587\u4ef6\u3002YAML \u6a21\u677f\u6709\u51e0\u79cd\u65b9\u6cd5\uff0c\u4f46\u6700\u57fa\u672c\u7684\u65b9\u6cd5\u662f\u641c\u7d22\u5e76\u66ff\u6362\u6211\u4eec\u5728 YAML \u6587\u4ef6\u4e2d\u4f7f\u7528\u5360\u4f4d\u7b26\u6765\u8868\u793a\u4e00\u4e9b\u503c\u7684\u5730\u65b9\u3002<\/p>\n

\u56e0\u6b64\uff0c\u56de\u5230\u6700\u521d\u7684\u4f8b\u5b50\uff0c\u6211\u4eec\u5c06\u6dfb\u52a0\u4e00\u4e2a\u5360\u4f4d\u7b26\u503c\uff0c\u5982 env \u5b57\u6bb5\u4e0b\u6240\u793a\uff1a<\/p>\n

apiVersion<\/span>:<\/span> v1\nkind<\/span>:<\/span> Pod\nmetadata<\/span>:<\/span>\n  name<\/span>:<\/span> spring-<\/span>pod\nspec<\/span>:<\/span>\n  containers<\/span>:<\/span>\n  \u2013 image<\/span>:<\/span> armo\/springapp:<\/span>example\n    name<\/span>:<\/span> spring-<\/span>app\n    env<\/span>:<\/span>\n    \u2013 name<\/span>:<\/span> ENV\n      value<\/span>:<\/span> %DEPLOYMENT_ENV%\n<\/code><\/pre>\n

\u901a\u8fc7\u5229\u7528 bash \u4e2d\u7684 sed \u547d\u4ee4\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u5904\u7406 YAML \u6587\u4ef6\u4e4b\u524d\u641c\u7d22\u5e76\u66ff\u6362\u8fd9\u4e9b\u503c\u3002\u7136\u800c\uff0c\u8fd9\u662f\u6700\u57fa\u672c\u548c\u6700\u4e0d\u65b9\u4fbf\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u60a8\u5fc5\u987b\u624b\u52a8\u6267\u884c\u5360\u4f4d\u7b26\u7684\u786c\u7f16\u7801\u3002<\/p>\n

\u4e00\u79cd\u66f4\u4fbf\u6377\u7684\u65b9\u6cd5\u662f\u5229\u7528\u50cf Helm \u8fd9\u6837\u7684\u5de5\u5177\u6765\u6784\u5efa\u548c\u7ba1\u7406\u6a21\u677f\u3002<\/p>\n

\u7ed3\u8bba<\/h3>\n

\u7531\u4e8e YAML \u7684\u7ed3\u6784\u53ca\u5176\u8bbe\u8ba1\u76ee\u6807\uff0c\u5b83\u662f Kubernetes \u914d\u7f6e\u7684\u6700\u4f73\u89e3\u51b3\u65b9\u6848\u3002\u589e\u5f3a\u7684\u53ef\u8bfb\u6027\u548c\u7b80\u6d01\u7684\u7ed3\u6784\u4f7f\u60a8\u5728\u6269\u5c55 Kubernetes \u914d\u7f6e\u65f6\uff0c\u4e0d\u4f1a\u8ff7\u5931\u5728\u6210\u5806\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u3002<\/p>\n

\u6b64\u5916\uff0c\u901a\u8fc7\u4e86\u89e3\u5982\u4f55\u58f0\u660e\u5f0f\u5730\u6784\u5efa Kubernetes \u5e94\u7528\u7a0b\u5e8f\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u7406\u89e3 Kubernetes \u5e94\u7528\u7a0b\u5e8f\u5982\u4f55\u4ee5\u53ca\u4e3a\u4ec0\u4e48\u8fd0\u884c\u7684\u673a\u5236\u3002\u5e76\u8003\u8651 YAML \u6a21\u677f\u7b49\u9ad8\u7ea7\u529f\u80fd\u6765\u5e2e\u52a9\u7b80\u5316\u5b9a\u4e49\u548c\u6784\u5efa Kubernetes \u5e94\u7528\u7a0b\u5e8f\u7684\u8fc7\u7a0b\u3002<\/p>\n


\n

\u805a\u7126\u4e91\u539f\u751f\u65b0\u6280\u672f\u3001\u65b0\u5b9e\u8df5\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u7fa4\u4f53\u8d62\u5728\u5f00\u53d1\u8303\u5f0f\u8f6c\u79fb\u7684\u65b0\u65f6\u4ee3\u3002\u6b22\u8fce\u5173\u6ce8CSDN\u4e91\u539f\u751f\u5fae\u4fe1\u516c\u4f17\u53f7\uff1acsdn-cloud<\/p>\n","protected":false},"excerpt":{"rendered":"kubernetes yaml\u751f\u6210\u5de5\u5177_k8s\u548cdocker\u533a\u522bYAML\u63d0\u4f9b\u4e86\u4e00\u79cd\u4ee5\u58f0\u660e\u5f0f\u914d\u7f6eKubernetes\u5e94\u7528\u7a0b\u5e8f\u7684\u65b9\u6cd5\uff0c\u8fd9\u4e9b\u58f0\u660e\u6027\u6587\u4ef6\u5141\u8bb8\u60a8\u6709\u6548\u5730...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8669"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=8669"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8669\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}