# 设置要安装命名空间 kubens infra # 添加helm仓库 helm repo add bitnami https://charts.bitnami.com/bitnami # 安装mysql helm install mysql bitnami/mysql #output WARNING: This chart is deprecated NAME: mysql LAST DEPLOYED: Mon May 31 15:04:17 2021 NAMESPACE: infra STATUS: deployed REVISION: 1 NOTES: MySQL can be accessed via port 3306 on the following DNS name from within your cluster: mysql.infra.svc.cluster.local
To get your root password run:
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace infra mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)
To connect to your database:
1. Run an Ubuntu pod that you can use as a client:
kubectl run -i --tty ubuntu --image=ubuntu:16.04 --restart=Never -- bash -il
# 安装Redis helm install redis bitnami/redis #output NAME: redis LAST DEPLOYED: Mon May 31 15:07:07 2021 NAMESPACE: infra STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: ** Please be patient while the chart is being deployed **
Redis(TM) can be accessed on the following DNS names from within your cluster:
redis-master.infra.svc.cluster.local for read/write operations (port 6379) redis-replicas.infra.svc.cluster.local for read-only operations (port 6379)
To get your password run:
export REDIS_PASSWORD=$(kubectl get secret --namespace infra redis -o jsonpath="{.data.redis-password}" | base64 --decode)
To connect to your Redis(TM) server:
1. Run a Redis(TM) pod that you can use as a client:
kubectl run --namespace infra redis-client --restart='Never' --env REDIS_PASSWORD=$REDIS_PASSWORD --image docker.io/bitnami/redis:6.2.3-debian-10-r22 --command -- sleep infinity
Use the following command to attach to the pod:
kubectl exec --tty -i redis-client \ --namespace infra -- bash
2. Connect using the Redis(TM) CLI: redis-cli -h redis-master -a $REDIS_PASSWORD redis-cli -h redis-replicas -a $REDIS_PASSWORD
To connect to your database from outside the cluster execute the following commands:
kubectl port-forward --namespace infra svc/redis-master 6379:6379 & redis-cli -h 127.0.0.1 -p 6379 -a $REDIS_PASSWORD
# 安装kafka helm install kafka bitnami/kafka # output NAME: kafka LAST DEPLOYED: Mon May 31 15:09:13 2021 NAMESPACE: infra STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: ** Please be patient while the chart is being deployed **
Kafka can be accessed by consumers via port 9092 on the following DNS name from within your cluster:
kafka.infra.svc.cluster.local
Each Kafka broker can be accessed by producers via port 9092 on the following DNS name(s) from within your cluster:
# 从阿里云拉取镜像并转换tag for i in `kubeadm config images list`; do imageName=${i#k8s.gcr.io/} docker pull registry.aliyuncs.com/google_containers/$imageName docker tag registry.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName docker rmi registry.aliyuncs.com/google_containers/$imageName done;
spec: replicas:1 selector: matchLabels: app:traefik template: metadata: labels: app:traefik spec: serviceAccountName:traefik-ingress-controller containers: -name:traefik image:traefik:v2.4 args: ---accesslog ---entrypoints.web.Address=:8000 ---entrypoints.websecure.Address=:4443 ---entrypoints.mysql.Address=:3306 ---providers.kubernetescrd ---certificatesresolvers.myresolver.acme.tlschallenge ---certificatesresolvers.myresolver.acme.email=foo@you.com ---certificatesresolvers.myresolver.acme.storage=acme.json # Please note that this is the staging Let's Encrypt server. # Once you get things working, you should remove that whole line altogether. ---certificatesresolvers.myresolver.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory ports: -name:web containerPort:8000 -name:websecure containerPort:4443 -name:admin containerPort:8080 -name:mysql containerPort:3306
The Service “traefik” is invalid: spec.ports[0].nodePort: Invalid value: 80: provided port is not in the valid range. The range of valid ports is 30000-32767
四、更改Kubernetes服务节点端口范围:
1)登录Docker VM:
1
docker run --rm -it --privileged --pid=host walkerlee/nsenter -t 1 -m -u -i -n sh
$ kubectl get po -o wide -n <namspace1> -n <namespace2> -n <namespace3>
4、显示当前默认的namespace
1
$ kubectl config view --minify | grep namespace
5、k8s常用的aliases别名
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
alias k='kubectl' alias kc='kubectl config view --minify | grep name' alias kdp='kubectl describe pod' alias krh='kubectl run --help | more' alias ugh='kubectl get --help | more' alias c='clear' alias ke='kubectl explain' alias kf='kubectl create -f' alias kg='kubectl get pods --show-labels' alias kr='kubectl replace -f' alias kh='kubectl --help | more' alias krh='kubectl run --help | more' alias ks='kubectl get namespaces' alias kga='k get pod --all-namespaces' alias kgaa='kubectl get all --show-labels'
6、VI配置,便于使用vi编辑YAML
创建 ~/.vimrc 并添加以下内容
1 2 3 4 5
set smarttab set expandtab set shiftwidth=4 set tabstop=4 set number
7、从kubectl命令创建YAML模板文件
1 2 3 4 5 6 7 8 9 10 11
kubectl run busybox --image=busybox --dry-run=client -o yaml --restart=Never > yamlfile.yaml