本文将分享制作Swift和Objective-CMixed的Pod的详细内容,并且还将对swift制作app进行详尽解释,此外,我们还将为大家带来关于.NETCorepod无法连接到Kubernete
本文将分享制作 Swift 和 Objective-C Mixed 的 Pod的详细内容,并且还将对swift制作app进行详尽解释,此外,我们还将为大家带来关于.NET Core pod 无法连接到 Kubernetes 中的 SQL Server pod、023. 掌握 Pod-Pod 扩容和缩容、CocoaPods pod install/ pod update( 安装/更新代码库)超级慢问题、CocoaPods pod install/pod update更新慢的问题的相关知识,希望对你有所帮助。
本文目录一览:- 制作 Swift 和 Objective-C Mixed 的 Pod(swift制作app)
- .NET Core pod 无法连接到 Kubernetes 中的 SQL Server pod
- 023. 掌握 Pod-Pod 扩容和缩容
- CocoaPods pod install/ pod update( 安装/更新代码库)超级慢问题
- CocoaPods pod install/pod update更新慢的问题
制作 Swift 和 Objective-C Mixed 的 Pod(swift制作app)
(点击上方公众号,可快速关注)
来源:南栀倾寒
www.jianshu.com/p/c7623c31d77b
如有好文章投稿,请点击 → 这里了解详情
知识背景
What is CocoaPods(https://guides.cocoapods.org/using/getting-started.html)
What did CocoaPods do?(https://guides.cocoapods.org/using/using-cocoapods.html)
In Xcode,with references directly from the ruby source,it:
Creates or updates a workspace.
Adds your project to the workspace if needed.
Adds the CocoaPods static library project to the workspace if needed.
Adds libPods.a to: targets => build phases => link with libraries.
Adds the CocoaPods Xcode configuration file to your app’s project.
Changes your app’s target configurations to be based on CocoaPods’s.
Adds a build phase to copy resources from any pods you installed to your app bundle. i.e. a ‘Script build phase’ after all other build phases with the following:
Shell: /bin/sh
Script: ${SRCROOT}/Pods/PodsResources.sh
大意是,CocoaPods是一个依赖管理工具,使用CocoaPods可以自动的去分析依赖,然后通过脚本去将第三方依赖复制编译为静态库然后链接进项目。~~~等。
制作Pod
有时候我们有把代码做成一个轮子给别人用情况,我们需要按照官方的教程Making CocoaPods去制作。
教程分为2类 :
发布公共Pod给所有开发者使用。
制作私有Pod。 方法较为简单。自行查阅资料即可。这里不再赘述。
Swift和Objective-C Mixed
参考官方的文档(文末指出),混编里面包含有2种调用情况:
Question1. Swift调用Objective-C
Question2. Objective-C调用Swift
这里我新建一个项目 命名为Mixed(Single View Application), 创建一个文件夹Classes用于存放源代码
创建一个Objective-C Class O 继承自NSObject 创建一个Swift Class S 继承自NSObject
Answer1: 为Swift源代码添加一个 XXX.h头文件这里为Mixed-Bridging-Header 在这个文件中导入需要访问的Objective-C 源代码的头文件。
headerConfig
有时候Xcode反应会稍微延迟一点。手动编译一下即可。做完这个配置,Swift即可访问Objective-C 源代码。
代码如图:
swiftAccessObjc
Answer2: Objective-C 访问Swift源代码 需要导入系统为项目生成的头文件,默认为Module+Swift.h 当然自己也是可以修改的, 导入之后,编译一下(Xcode有时候有缓存,没事就应该编译一下
总结
以上是小编为你收集整理的制作 Swift 和 Objective-C Mixed 的 Pod全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
.NET Core pod 无法连接到 Kubernetes 中的 SQL Server pod
如何解决.NET Core pod 无法连接到 Kubernetes 中的 SQL Server pod
我有一个 .NET Core pod,需要访问 Kubernetes(docker-desktop)中的 sql Server pod。 使用端口转发,我可以从 sql Server Management Studio 连接到该 sql Server。但是当我尝试从 .NET Core pod 连接时,它说
未找到或无法访问服务器
这是日志中的错误
[04:28:38 Error] Microsoft.EntityFrameworkCore.Database.Connection
An error occurred using the connection to database ''MyTestDatabase'' on server ''tcp:sqlserver-service,1433''.
[04:28:38 Error] Microsoft.EntityFrameworkCore.Query
An exception occurred while iterating over the results of a query for context type ''Web.Data.ApplicationDbContext''.
Microsoft.Data.sqlClient.sqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to sql Server. The server was not found or was not accessible. Verify that the instance name is correct and that sql Server is configured to allow remote connections. (provider: TCP Provider,error: 40 - Could not open a connection to sql Server)
我在容器中的连接字符串
Server=tcp:sqlserver-service,1433;User ID=sa;Password=myPass12;Initial Catalog=MyTestDatabase;MultipleActiveResultSets=true;Connection Timeout=30;
sql Server 部署 yml 文件
apiVersion: v1
kind: PersistentVolume
Metadata:
name: sqldata
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteMany
hostPath:
path: "/sqldata"
---
apiVersion: v1
kind: PersistentVolumeClaim
Metadata:
name: dbclaim
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
Metadata:
name: sqlserver
spec:
replicas: 1
selector:
matchLabels:
app: sqlserver
template:
Metadata:
labels:
app: sqlserver
spec:
volumes:
- name: sqldata-storage
persistentVolumeClaim:
claimName: dbclaim
terminationGracePeriodSeconds: 10
initContainers:
- name: volume-permissions
image: busyBox
command: ["sh","-c","chown -R 10001:0 /var/opt/mssql"]
volumeMounts:
- mountPath: "/var/opt/mssql"
name: sqldata-storage
containers:
- name: sqlserver1
image: mcr.microsoft.com/mssql/server
ports:
- containerPort: 1433
env:
- name: MSsql_PID
value: "Developer"
- name: SA_PASSWORD
value: "myPass12"
- name: ACCEPT_EULA
value: "Y"
volumeMounts:
- mountPath: "/var/opt/mssql/data"
name: sqldata-storage
---
apiVersion: v1
kind: Service
Metadata:
name: sqlserver-service
spec:
ports:
- name: sqlserver
port: 1433
targetPort: 1433
protocol: TCP
selector:
name: sqlserver
type: LoadBalancer
从 sql Server Management Studio 连接
我肯定错过了什么。
提前致谢
解决方法
这是我的错。实际上服务的选择器是错误的。
selector:
name: sqlserver
应该是
selector:
app: sqlserver
谢谢大家
023. 掌握 Pod-Pod 扩容和缩容
一 Pod 的扩容和缩容
1.1 手动缩容和扩容
1 [root@uk8s-m-01 study]# vi nginx-deployment.yaml
2 apiVersion: apps/v1beta1
3 kind: Deployment
4 metadata:
5 name: nginx-deployment
6 spec:
7 replicas: 3
8 template:
9 metadata:
10 labels:
11 app: nginx
12 spec:
13 containers:
14 - name: nginx
15 image: nginx:1.7.9
16 ports:
17 - containerPort: 80
1 [root@uk8s-m-01 study]# kubectl create -f nginx-deployment.yaml
2 [root@uk8s-m-01 study]# kubectl scale deployment nginx-deployment --replicas=5 #扩容至5个
3 [root@uk8s-m-01 study]# kubectl get pods #查看扩容后的Pod

1 [root@uk8s-m-01 study]# kubectl scale deployment nginx-deployment --replicas=2 #缩容至2个
2 [root@uk8s-m-01 study]# kubectl get pods

1.2 自动扩容机制
- HPA 原理

- HPA 指标类型
- 扩缩容算法
- Pod 正在被删除(设置了删除时间戳):将不会计入目标 Pod 副本数量。
- Pod 的当前指标值无法获得:本次探测不会将这个 Pod 纳入目标 Pod 副本数量,后续的探测会被重新纳入计算范围。
- 如果指标类型是 CPU 使用率,则对于正在启动但是还未达到 Ready 状态的 Pod,也暂时不会纳入目标副本数量范围。
1.3 HorizontalPodAutoscaler
1 [root@uk8s-m-01 study]# vi php-apache-autoscaling-v1.yaml
2 apiVersion: autoscaling/v1
3 kind: HorizontalPodAutoscaler
4 metadata:
5 name: php-apache
6 spec:
7 scaleTargetRef:
8 apiVersion: apps/v1
9 kind: Deployment
10 name: php-apache
11 minReplicas: 1
12 maxReplicas: 10
13 targetCPUUtilizationPercentage: 50
1 [root@uk8s-m-01 study]# vi php-apache-autoscaling-v2.yaml
2 apiVersion: autoscaling/v2beta2
3 kind: HorizontalPodAutoscaler
4 metadata:
5 name: php-apache
6 spec:
7 scaleTargetRef:
8 apiVersion: apps/v1
9 kind: Deployment
10 name: php-apache
11 minReplicas: 1
12 maxReplicas: 10
13 metrics:
14 - type: Resource
15 resource:
16 name: cpu
17 target:
18 type: Utilization
19 averageUtilization: 50
- metrics 中的 type(指标类型)设置为以下几种:
- Resource:基于资源的指标值,可以设置的资源为 CPU 和内存。
- Pods:基于 Pod 的指标,系统将对全部 Pod 副本的指标值进行平均值计算。
- Object:基于某种资源对象(如 Ingress)的指标或应用系统的任意自定义指标。
1 metrics:
2 - type: Pods
3 pods:
4 metrics:
5 name: packets-per-second
6 target:
7 type: AverageValue
8 averageValue: 1k
CocoaPods pod install/ pod update( 安装/更新代码库)超级慢问题
最近使用CocoaPods来添加/删除第三方类库时,无论是执行pod install还是pod update都无限卡住了。原因在于当执行以上两个命令的时候会升级CocoaPods的spec仓库,因此解决此问题的办法就是忽略这个监测升级CocoaPods的仓库的步骤,那么怎么来忽略这个步骤来提升安装或更新步骤呢,
只需要在命令中加个参数即可,命令如下:
$ pod install --verbose --no-repo-update
$ pod update --verbose --no-repo-update
或者
$ pod install --no-repo-update
$ pod update --no-repo-update
解决办法 : $ pod repo update
原因:你本地的repo库太长时间没有更新了
题外:gem版本过老
gem是管理Ruby库和程序的标准包,如果它的版本过低也可能导致安装失败,解决方案自然是升级gem,执行下述命令即可:
$ sudo gem update --system
CocoaPods pod install/pod update更新慢的问题
最近使用CocoaPods来添加第三方类库,无论是执行pod install还是pod update都卡在了Analyzing dependencies不动
原因在于当执行以上两个命令的时候会升级CocoaPods的spec仓库,加一个参数可以省略这一步,然后速度就会提升不少。加参数的命令如下:
pod install --verbose --no-repo-update
pod update --verbose --no-repo-update
关于制作 Swift 和 Objective-C Mixed 的 Pod和swift制作app的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于.NET Core pod 无法连接到 Kubernetes 中的 SQL Server pod、023. 掌握 Pod-Pod 扩容和缩容、CocoaPods pod install/ pod update( 安装/更新代码库)超级慢问题、CocoaPods pod install/pod update更新慢的问题的相关知识,请在本站寻找。
本文标签: