# k8s **Repository Path**: levy_de/k8s ## Basic Information - **Project Name**: k8s - **Description**: k8s安装常用软件 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2022-10-27 - **Last Updated**: 2025-01-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 本地访问k8s的apisix-dashboard ## 将集群的pod端口映射到本地 ```shell kubectl -n ${命名空间名称} port-forward ${pod名称} ${本地端口}:${容器端口} # eg:kubectl -n thingsboard port-forward timescaledb-0 30100:5432 ``` - 导出deployment.yaml ```shell kubectl create deployment web1 --image=nginx --dry-run -o yaml > deployment.yaml ``` - 导出service.yaml ```shell kubectl expose deployment web1 --port=80 --target-port=80 --type=NodePort --dry-run -o yaml > service.yaml ``` ## helm常用命令 - helm官方文档: [官网](https://helm.sh/zh/docs/) - 生成chart文件 ```shell helm create # eg: helm create apisix ``` - 安装应用 ```shell helm install # eg: helm install apisix apisix/ ``` - 只查看chart内容 ,不安装 ```shell helm install --debug --dry-run goodly-guppy ``` - 指定某个value文件 ```shell helm install -n -f .yaml # eg: helm install apisix apisix/ -f value.yaml ``` - 应用升级 ```shell helm upgrade -n -f .yaml # eg: helm upgrade apisix apisix/ ``` - 卸载应用 ```shell helm uninstall -n # eg: helm uninstall apisix apisix/ ``` - yaml文件高效复用 ``` 通过value.yaml传递参数动态渲染模板 通过{{ .Values.变量名称 }}引用 {{ .Release.Name }}引用发布名称 ``` - 查看实际加载的模板内容 ``` helm get manifest ``` - helm内置对象 - Release ``` Release.Name: release名称 Release.Namespace: 版本中包含的命名空间(如果manifest没有覆盖的话) Release.IsUpgrade: 如果当前操作是升级或回滚的话,该值将被设置为true Release.IsInstall: 如果当前操作是安装的话,该值将被设置为true Release.Revision: 此次修订的版本号。安装时是1,每次升级或回滚都会自增 Release.Service: 该service用来渲染当前模板 ``` - Values ``` Values对象是从values.yaml文件和用户提供的文件传进模板的。默认为空 ``` - Files ``` Files.Get 通过文件名获取文件的方法。 (.Files.Getconfig.ini) Files.GetBytes 用字节数组代替字符串获取文件内容的方法。 对图片之类的文件很有用 Files.Glob 用给定的shell glob模式匹配文件名返回文件列表的方法 Files.Lines 逐行读取文件内容的方法。迭代文件中每一行时很有用 Files.AsSecrets 使用Base 64编码字符串返回文件体的方法 Files.AsConfig 使用YAML格式返回文件体的方法 ``` ## kubectl常用命令 - 查看节点 ```shell kubectl get nodes ``` - 创建命名空间 ```shell kubectl create namespace # 或 kubectl create ns ``` - 删除命名空间 ```shell kubectl delete namespace 或 kubectl delete ns ``` - 查看某个命名空间详细描述 ```shell kubectl describe namespace ``` - 查看当前命名空间 ```shell kubecctl get namespace ``` - 创建应用 ```shell kubectl apply -f .yaml -n ``` - 查看pod ```shell # 1. 查看所有pod kubectl get pods -a -w --show-labels # -w: 实时监控pod状态 # -a: 查看所有pod,部分命名空间 # --show-labels: 显示标签 # 2. 查看指定命名空间下的pod kubectl get pods -n ``` - 删除pod ```shell kubectl delete pod -n ``` - 查看日志 ```shell kubectl logs -f -f: 日志追加显示 ``` - 查看pod详细信息 ```shell kubectl get pod -o wide ``` - 进入容器内部 ```shell kubectl exec -it /bin/bash ``` - 扩容/缩容 ```shell # 扩容 kubectl scale deploy/dep-name --replicas=3 # 缩容 kubectl scale deploy/dep-name --replicas=1 ``` - 查看历史版本 ```shell kubectl rollout history deploy/dep-name ``` - 版本回退 ```shell kubectl rollout undo deploy/dep-name --to-revision=1 ``` - 创建配置集 ```shell # cm: configmap的缩写 # kubectl create cm --from-file= kubectl create cm redis-conf --from-file=redis.conf ``` - 创建秘钥 ```shell kubectl create secret docker-registry docker-req 内容 ``` # kubeSphere多机器部署 - 提前准备好三台服务器,并非设置好ip地址,此版本为v3.1.1 - 下载KubeKey ```shell export KKZONE=cn curl -sfL https://get-kk.kubesphere.io | VERSION=v1.1.1 sh - chmod +x kk ``` - 创建集群配置文件 ```shell ./kk create config --with-kubernetes v1.20.4 --with-kubesphere v3.1.1 ``` - 修改下载的文件config-sample.yaml ```shell vim config-sample.yaml ``` - 以下为配置文件参考内容 ```yaml apiVersion: kubekey.kubesphere.io/v1alpha1 kind: Cluster metadata: name: sample spec: hosts: - {name: master, address: 192.168.88.140, internalAddress: 192.168.88.140, user: root, password: } - {name: node1, address: 192.168.88.141, internalAddress: 192.168.88.141, user: root, password: } - {name: node2, address: 192.168.88.142, internalAddress: 192.168.88.142, user: root, password: } roleGroups: etcd: - master master: - master worker: - node1 - node2 controlPlaneEndpoint: domain: lb.kubesphere.local address: "" port: 6443 kubernetes: version: v1.20.4 imageRepo: kubesphere clusterName: cluster.local network: plugin: calico kubePodsCIDR: 10.233.64.0/18 kubeServiceCIDR: 10.233.0.0/18 registry: registryMirrors: [] insecureRegistries: [] addons: [] --- apiVersion: installer.kubesphere.io/v1alpha1 kind: ClusterConfiguration metadata: name: ks-installer namespace: kubesphere-system labels: version: v3.1.1 spec: persistence: storageClass: "" authentication: jwtSecret: "" zone: "" local_registry: "" etcd: monitoring: true endpointIps: localhost port: 2379 tlsEnable: true common: redis: enabled: false redisVolumSize: 2Gi openldap: enabled: false openldapVolumeSize: 2Gi minioVolumeSize: 20Gi monitoring: endpoint: http://prometheus-operated.kubesphere-monitoring-system.svc:9090 es: elasticsearchMasterVolumeSize: 4Gi elasticsearchDataVolumeSize: 20Gi logMaxAge: 7 elkPrefix: logstash basicAuth: enabled: false username: "" password: "" externalElasticsearchUrl: "" externalElasticsearchPort: "" console: enableMultiLogin: true port: 30880 alerting: enabled: false # thanosruler: # replicas: 1 # resources: {} auditing: enabled: false devops: enabled: true jenkinsMemoryLim: 2Gi jenkinsMemoryReq: 1500Mi jenkinsVolumeSize: 8Gi jenkinsJavaOpts_Xms: 512m jenkinsJavaOpts_Xmx: 512m jenkinsJavaOpts_MaxRAM: 2g events: enabled: false ruler: enabled: true replicas: 2 logging: enabled: false logsidecar: enabled: true replicas: 2 metrics_server: enabled: false monitoring: storageClass: "" prometheusMemoryRequest: 400Mi prometheusVolumeSize: 20Gi multicluster: clusterRole: none network: networkpolicy: enabled: false ippool: type: none topology: type: none openpitrix: store: enabled: true servicemesh: enabled: false kubeedge: enabled: false cloudCore: nodeSelector: {"node-role.kubernetes.io/worker": ""} tolerations: [] cloudhubPort: "10000" cloudhubQuicPort: "10001" cloudhubHttpsPort: "10002" cloudstreamPort: "10003" tunnelPort: "10004" cloudHub: advertiseAddress: - "" nodeLimit: "100" service: cloudhubNodePort: "30000" cloudhubQuicNodePort: "30001" cloudhubHttpsNodePort: "30002" cloudstreamNodePort: "30003" tunnelNodePort: "30004" edgeWatcher: nodeSelector: {"node-role.kubernetes.io/worker": ""} tolerations: [] edgeWatcherAgent: nodeSelector: {"node-role.kubernetes.io/worker": ""} tolerations: [] ``` - 创建集群 ```shell ./kk create cluster -f config-sample.yaml ``` - 查看进度 ```shell kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f ``` - 安装成功截图 ![img.png](static/imgs/img.png)