-
拉取镜像
docker pull kennethreitz/httpbin:latest
-
查看本地是否存在存在镜像
docker images | grep kennethreitz/httpbin:latest
-
创建 deployment,指定镜像
ymlapiVersion: apps/v1 kind: Deployment metadata: labels: app: httpbin name: mm-httpbin namespace: mm-test spec: replicas: 1 selector: matchLabels: app: httpbin template: metadata: labels: app: httpbin spec: containers: - name: mm-httpbin image: kennethreitz/httpbin:latest resources: limits: cpu: "1" memory: 1Gi requests: cpu: 200m memory: 256Mi
-
创建 service,关联 pod
ymlapiVersion: v1 kind: Service metadata: labels: app: httpbin name: mm-httpbin namespace: mm-test spec: selector: app: httpbin type: ClusterIP ports: - name: "18888" port: 18888 targetPort: 80 protocol: 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