共计 2083 个字符,预计需要花费 6 分钟才能阅读完成。
1、在 k8s 中部署利用流程
- 制作镜像(个别通过 Dockerfile)
1、hub.docker.com(规范镜像)
2、满足个性化定制化需要(标准化、调优参数等) - 控制器治理 Pod
- 裸露应用服务
- 对外公布利用
- 治理日志 / 集群监控
2、应用 Deployment 部署 Java 利用
[root@k8s-m ~]# docker run -d --name=web -p 80:80 e a=test nginx
[root@k8s-m ~]# kubectl create --help
[root@k8s-m ~]# kubectl create deployment --help
[root@k8s-m ~]# docker pull yejf/java-demo
[root@k8s-m ~]# kubectl create deployment web --image=yejf/java-demo:latest
[root@k8s-m ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-f89759699-bxftk 1/1 Running 0 17h
web-7757ff5c-pt6jd 1/1 Running 0 83s
[root@k8s-m ~]# kubectl get deploy,pods
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx 1/1 1 1 2d16h
deployment.apps/web 1/1 1 1 2m53s
NAME READY STATUS RESTARTS AGE
pod/nginx-f89759699-bxftk 1/1 Running 0 17h
pod/web-7757ff5c-pt6jd 1/1 Running 0 2m53s
[root@k8s-m ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-f89759699-bxftk 1/1 Running 0 17h 10.244.215.77 k8s-n1 <none> <none>
web-7757ff5c-pt6jd 1/1 Running 0 5m55s 10.244.111.205 k8s-n2 <none> <none>
[root@k8s-m ~]#
[root@k8s-m ~]# kubectl expose deployment web --port=80 --target-port=8080 --name=web --type=NodePort
[root@k8s-m ~]# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d17h
nginx NodePort 10.100.4.40 <none> 80:30026/TCP 2d16h
web NodePort 10.104.68.193 <none> 80:32583/TCP 47s
[root@k8s-m ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d17h
nginx NodePort 10.100.4.40 <none> 80:30026/TCP 2d16h
web NodePort 10.104.68.193 <none> 80:32583/TCP 51s
http://192.168.X.63:32853
3、应用 YAML 部署 Java 利用
# vim java-demo.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: java-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: java-demo
template:
metadata:
labels:
app: java-demo
spec:
containers:
- name: nginx
image: yejf/java-demo
ports:
[root@k8s-m ~]# kubectl apply -f java-demo.yaml
deployment.apps/java-demo created
[root@k8s-m ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
java-demo 1/1 1 1 41s
nginx 1/1 1 1 2d17h
web 1/1 1 1 27m
[root@k8s-m ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
java-demo-d9787d978-7dcp6 1/1 Running 0 50s
nginx-f89759699-bxftk 1/1 Running 0 18h
web-7757ff5c-pt6jd 1/1 Running 0 28m
2、利用部署 / 降级、回滚和弹性伸缩
正文完