kubernetes部署项目

1、安装minikube

参考单机版kubernetes

2、部署镜像

参考jib部署到阿里云容器镜像

3、项目部署

3.1 本地拉取镜像

>docker login -u 用户名 -p 密码 registry-vpc.us-west-1.aliyuncs.com #登录阿里云
>docker pull registry-vpc.us-west-1.aliyuncs.com/xxx/com.jib.demo:latest #拉取镜像

3.2 创建deployment 对象

编写com-jib-demo.yml

apiVersion: v1
kind: Service #service
metadata:
  name: com-jib-demo-service
  labels:
    app: com-jib-demo
spec:
  type: LoadBalancer
  ports:
  - port: 8080
    nodePort: 30000 #集群外就可以使用kubernetes任意一个节点的IP加上30000端口访问该服务了
  selector:
    app: com-jib-demo
---
apiVersion: apps/v1
kind: Deployment #Deployment
metadata:
  name: com-jib-demo-deployment
  labels:
    app: com-jib-demo
spec:
  replicas: 3
  selector:
    matchLabels:
      app: com-jib-demo
  template:
    metadata:
      labels:
        app: com-jib-demo
    spec:  
      containers:
        - name: com-jib-demo
          image: registry-vpc.us-west-1.aliyuncs.com/docker-wei/com.jib.demo:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080

创建集群

>kubectl apply -f com-jib-demo.yml
>kubectl expose deployment com-jib-demo-deployment --type=NodePort #暴露端口
>minikube service com-jib-demo-deployment --url #获取访问url

4、命令参考

中文:http://docs.kubernetes.org.cn/683.html

英文:https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands

 

你可能感兴趣的:(k8s,docker)