目录

获取node节点

获取service

获取pod

部署: apply yaml

替换:

删除:delete

查看Pod日志:

获取resource相关信息:

进入Pod:

重新部署

扩展实例:

错误记录:

Forbidden

ClusterRoleBack Error

启动spring cloud k8s,出现ribbon未找到错误:

Create a static IP address

附教程链接:


获取node节点

kubectl get nodes

或:
kubectl get nodes -n mytest

-n: 命名空间,以下的命名基本都可以指定执行的命名空间

获取service

kubectl get svc

获取pod

kubectl get pods

部署: apply yaml

kubectl apply -f azure-vote.yaml

apply命令提供了比patch,edit等更严格的更新resource的方式。通过apply,用户可以将resource的configuration使用source control的方式维护在版本库中。每次有更新时,将配置文件push到server,然后使用kubectl apply将更新应用到resource。kubernetes会在引用更新前将当前配置文件中的配置同已经应用的配置做比较,并只更新更改的部分,而不会主动更改任何用户未指定的部分。 
     apply命令的使用方式同replace相同,不同的是,apply不会删除原有resource,然后创建新的。apply直接在原有resource的基础上进行更新。同时kubectl apply还会resource中添加一条注释,标记当前的apply。类似于git操作。 

替换:

kubectl replace -f xxxx.yaml

replace命令用于对已有资源进行更新、替换。

删除:delete

kubectl delete -f xxxxx.yaml

根据resource删除resource

查看Pod日志:

kubectl logs <your-pod-name>

或,实时查看日志:
kubectl logs --tail 200 -f <your-pod-name>

  • -f:实时
  • -tail:指定显示行数

获取resource相关信息:

kubectl describe pod <your-pod-name>

进入Pod:

kubectl exec -it <your-pod-name> /bin/sh -n upswmpdevns

Future instead
kubectl exec -it <your-pod-name> -- /bin/sh

重新部署

kubectl rollout restart deploy <your-deploy-name>

扩展实例:

kubectl scale --replicas=2 deployment/<your-service-name>

错误记录:

Forbidden

Forbidden!Configured service account doesn't have access. Service account may have been revoked, User “system:serviceaccount:mynamespacetest:default” cannot list resource "services" in API group "" in the namespace

解决办法:

设置权限:

kubectl create clusterrolebinding project-service-binding --clusterrole cluster-admin --serviceaccount=mynamespacetest:default --namespace=mynamespacetest

或:

Create a serviceaccount:
kubectl create serviceaccount spark

Give the service account the edit role on the cluster:
kubectl create clusterrolebinding spark-role --clusterrole=edit --serviceaccount=default:spark --namespace=default

Run spark submit with the following flag, in order to run it with the (just created(service account)
--conf spark.kubernetes.authenticate.driver.serviceAccountName=spark

或:

kubectl apply -f aks-create-role.yaml

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: default
  name: service-reader
rules:
- apiGroups: [""] # "" indicates the core API group
  resources: ["services"]
  verbs: ["get", "watch", "list"]

kubectl create clusterrolebinding service-reader-pod \
  --clusterrole=service-reader  \
  --serviceaccount=mynamespacetest:default

ClusterRoleBack Error

原因:
yaml设置的内存过小,导致启动失败
解决:

增加内存配置

          resources: # https://docs.microsoft.com/en-us/azure/aks/developer-best-practices-resource-management
            requests: # Set amount of CPU and memory that the pod needs on a regular basis.
              cpu: 512m
              memory: 2048Mi
            limits: # The maximum amount of CPU and memory that a pod can use.
              cpu: 512m
              memory: 2048Mi

启动spring cloud k8s,出现ribbon未找到错误:

原因:
spring cloud k8s需要重新引入ribbon依赖
解决:
引入依赖spring-cloud-starter-kubernetes-ribbon

Create a static IP address

https://docs.microsoft.com/en-us/azure/aks/static-ip#before-you-begin

附教程链接:

AKS教程
https://docs.microsoft.com/zh-cn/azure/aks/kubernetes-walkthrough-portal

AKS MINIKUBE
https://minikube.sigs.k8s.io/docs/start/

spring-cloud-kubernetes
https://github.com/spring-cloud/spring-cloud-kubernetes

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐