创建一个应用:
k8s增删查改:
pod创建:
kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --replicas=1
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-deploy-55d8d67cf-b7cct 1/1 Running 0 2m20s 10.244.1.2 k8s-node1 <none> <none>
curl 10.244.1.2
service创建:
[root@k8s-master ~]# kubectl expose deployment nginx-deploy --name=nginx --port=80 --target-port=80 --protocol=TCP
service/nginx exposed
[root@k8s-master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 148m
nginx ClusterIP 10.104.99.136 <none> 80/TCP 29s
[root@k8s-master ~]# kubectl run client --image=busybox --replicas=1 -it --restart=Never
kubectl scaled --replicas=3 deployment myapp
滚动更新:通过更新镜像的方式
[root@k8s-master ~]# kubectl set image deployment myapp myapp=ikubernetes/myapp:v2
查看滚动更新的过程:
[root@k8s-master ~]# kubectl rollout status deployment myapp
回滚:(不指定deplyment则默认回滚到上一个版本)
[root@k8s-master ~]# kubectl rollout ondo deployment myapp
集群外部访问:
修改service 类型
[root@k8s-master ~]# kubectl edit svc nginx
ClusterIP 只是集群内部访问:
type: NodePort 可以外部访问
[root@k8s-master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3h7m
nginx NodePort 10.104.99.136 <none> 80:31716/TCP 39m
访问节点ip+31316 即可访问nginx