目录
环境:(docker ,k8s集群),继续上次docker 启动的java程序的镜像为例(https://www.cnblogs.com/levcon/p/12442662.html)
将制作的镜像推送到docker的私有仓库
docker tag demo-img:latest localhost:5000/demo-img:1.0 docker push localhost:5000/demo-img:1.0
k8s部署该镜像
k8s创建命名空间及secret
创建命名空间cl-test,这里名字根据自己的命名规范自己定义,我这是测试用的 kubectl create namespace cl-test 创建完ns后,我们要给这个ns创建secret kubectl create secret docker-registry regcred --docker-server=your resroty ip:5000 --docker-username=root --docker-password=xxxx@ --docker-email=xxxx@163.com -n cl-test 控制台返回“secret/regcred created”表示创建成功
创建demo服务的yaml文件,我们service和deployment放在一个yaml文件中
--- apiVersion: v1 kind: Service metadata: name: demo-service namespace: cl-test labels: app: demo-service spec: type: NodePort ports: - port: 8701 targetPort: 8701 protocol: TCP name: http selector: app: demo-deployment --- apiVersion: apps/v1 kind: Deployment metadata: name: demo-deployment namespace: cl-test spec: selector: matchLabels: app: demo-pod replicas: 1 template: metadata: labels: app: demo-pod spec: containers: - name: demo-container image: localhost:5000/demo-img:1.0 #本地私有镜像库的镜像名称+版本 ports: - containerPort: 8701
启动
kubectl create -f demo.yaml
查看pod
kubectl get pod -n cl-test
pod日志查看,正是我们之前java启动时所展示的日志
来源:https://www.cnblogs.com/levcon/p/12641376.html