k8s deployment docker container

Environment: (docker, k8s cluster), mirroring java program continued last docker start example ( https://www.cnblogs.com/levcon/p/12442662.html )

The produced image pushed to the docker's private warehouse


docker tag demo-img:latest localhost:5000/demo-img:1.0

docker push localhost:5000/demo-img:1.0

k8s deploy the image

k8s create a namespace and 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@ [email protected] -n cl-test

控制台返回“secret/regcred created”表示创建成功

Create demo services yaml file, and deployment of our service on a yaml file


---

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

start up


kubectl create  -f demo.yaml

View pod


kubectl get pod -n cl-test

pod log viewer, it is when we start the show before java log

Guess you like

Origin www.cnblogs.com/levcon/p/12641376.html