需机器已部署好k8s和docker的环境
docker tag nginx:test harbor:test-nginx docker push harbor:test-nginx
#nginx-test为本次实验创建的测试命名空间
kubectl create namespace nginx-test
kubectl create secret docker-registry regcred --docker-server=harbor --docker-username=yourname --docker-password=yourpassword -n nginx-test
控制台返回“secret/regcred created”表示创建成功
--- apiVersion: v1 kind: Service metadata: name: nginx-service namespace: nginx-test labels: app: demo-service spec: type: NodePort ports: - port: 8800 targetPort: 80 protocol: TCP name: http selector: app: demo-pod --- apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment namespace: nginx-test spec: selector: matchLabels: app: demo-pod replicas: 1 template: metadata: labels: app: demo-pod spec: containers: - name: demo-container image: harbor:test-nginx #本地私有镜像库的镜像名称+版本 ports: - containerPort: 8800 hostPort: 8800
kubectl create -f test-nginx.yaml
[root@k8s001 test-nginx]# kubectl get pod -n nginx-test NAME READY STATUS RESTARTS AGE demo-deployment-6b7647579-9p5f7 1/1 Running 0 44m nginx-deployment-59c577b48f-c5q6q 1/1 Running 0 14m
至此,完成docker容器部署。
原文:https://www.cnblogs.com/lybj/p/14962639.html