Deploy Application to Alibaba ASK (Serverless Kubernetes) Cluster
2021年01月10日
# vim nginx.yaml
Make sure SNAT resource is configured for the ASK environment.
# kubectl apply -f nginx.yaml
查看Pod状态
# kubectl get pod
查看Serivce状态
# kubectl get svc
通过SLB IP访问Nginx应用
# curl 8.xxx.xx.55
扩容Deployment
查看Deployment
# kubectl get deploy
扩容Deployment
# kubectl scale deploy nginx-deploy --replicas=10
查看扩容后的Pod
# kubectl get pod
配置HPA,可以让应用随着负载压力自动进行弹性扩容。当应用的CPU负载增高时,将水平扩容出更多的Pod副本
将应用副本缩容到1个
# kubectl scale deploy nginx-deploy --replicas=1
查看Pod
# kubectl get pod
配置HPA
# kubectl autoscale deployment nginx-deploy --cpu-percent=50 --min=1 --max=10
查看HPA
# kubectl get hpa
References
一键创建Nginx在线应用
Configure Access to Multiple Clusters
-
-
For multiple K8S cluster environments, create the kube config file.
# vim /tmp/kubeconfig
The KUBECONFIG environment variable is a list of paths to configuration files. If you have a $HOME/.kube/config file, set it to your KUBECONFIG environment variable.
# export KUBECONFIG=$HOME/.kube/config
Append /tmp/kubeconfig to your KUBECONFIG environment variable.
# export KUBECONFIG=$KUBECONFIG:/tmp/kubeconfig
# kubectl get nodes
NAME STATUS ROLES AGE VERSION virtual-kubelet-cn-beijing-h Ready agent 3d23h v1.18.8-aliyun.1
# vim nginx.yaml
apiVersion: v1 kind: Service metadata: name: nginx-service spec: ports: - port: 80 protocol: TCP selector: app: nginx type: LoadBalancer --- apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deploy labels: app: nginx spec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:alpine ports: - containerPort: 80 resources: requests: cpu: "2" memory: "4Gi"
Make sure SNAT resource is configured for the ASK environment.
# kubectl apply -f nginx.yaml
service/nginx-service created deployment.apps/nginx-deploy created
查看Pod状态
# kubectl get pod
NAME READY STATUS RESTARTS AGE nginx-deploy-cb9fdfbb9-l9g4m 1/1 Running 0 66s nginx-deploy-cb9fdfbb9-rkp2t 1/1 Running 0 66s
查看Serivce状态
# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 172.21.0.1 <none> 443/TCP 3d23h nginx-service LoadBalancer 172.21.10.52 8.xxx.xx.55 80:31763/TCP 2m14s
通过SLB IP访问Nginx应用
# curl 8.xxx.xx.55
<!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
扩容Deployment
查看Deployment
# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE nginx-deploy 2/2 2 2 8m40s
扩容Deployment
# kubectl scale deploy nginx-deploy --replicas=10
deployment.apps/nginx-deploy scaled
查看扩容后的Pod
# kubectl get pod
NAME READY STATUS RESTARTS AGE nginx-deploy-cb9fdfbb9-24dsd 1/1 Running 0 70s nginx-deploy-cb9fdfbb9-76b8g 1/1 Running 0 70s nginx-deploy-cb9fdfbb9-f5nsz 1/1 Running 0 70s nginx-deploy-cb9fdfbb9-k7gzp 1/1 Running 0 70s nginx-deploy-cb9fdfbb9-l9g4m 1/1 Running 0 11m nginx-deploy-cb9fdfbb9-mgmmp 1/1 Running 0 70s nginx-deploy-cb9fdfbb9-mzf2k 1/1 Running 0 70s nginx-deploy-cb9fdfbb9-nfqj7 1/1 Running 0 70s nginx-deploy-cb9fdfbb9-rkp2t 1/1 Running 0 11m nginx-deploy-cb9fdfbb9-scvxj 1/1 Running 0 70s
配置HPA,可以让应用随着负载压力自动进行弹性扩容。当应用的CPU负载增高时,将水平扩容出更多的Pod副本
将应用副本缩容到1个
# kubectl scale deploy nginx-deploy --replicas=1
deployment.apps/nginx-deploy scaled
查看Pod
# kubectl get pod
NAME READY STATUS RESTARTS AGE nginx-deploy-cb9fdfbb9-rkp2t 1/1 Running 0 12m
配置HPA
# kubectl autoscale deployment nginx-deploy --cpu-percent=50 --min=1 --max=10
horizontalpodautoscaler.autoscaling/nginx-deploy autoscaled
查看HPA
# kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE nginx-deploy Deployment/nginx-deploy <unknown>/50% 1 10 1 35s
References
一键创建Nginx在线应用
Configure Access to Multiple Clusters
-