-
拉取镜像
docker pull kennethreitz/httpbin:latest
-
查看本地是否存在存在镜像
docker images | grep kennethreitz/httpbin:latest
-
创建 deployment,指定镜像
apiVersion: apps/v1 kind: Deployment metadata:labels:app: httpbinname: mm-httpbinnamespace: mm-test spec:replicas: 1selector:matchLabels:app: httpbintemplate:metadata:labels:app: httpbinspec:containers:- name: mm-httpbinimage: kennethreitz/httpbin:latestresources:limits:cpu: "1"memory: 1Girequests:cpu: 200mmemory: 256Mi
-
创建 service,关联 pod
apiVersion: v1 kind: Service metadata:labels:app: httpbinname: mm-httpbinnamespace: mm-test spec:selector:app: httpbintype: ClusterIPports:- name: "18888"port: 18888targetPort: 80protocol: TCP
-
修改 service 的类型为
NodePort
kubectl -n mm-test edit svc mm-httpbin
-
查看 service 的 nodeport 端口号,并通过 cmd、浏览器或 postman 测试
- cmd 测试
马赛克为 k8s 集群任一节点的 ip(具体搜索 k8s service nodeport 作用)
- 浏览器测试
- postman 测试
具体 yml 文件资源下载:https://download.csdn.net/download/qq_44140067/88651208